Skip to content

Commit

Permalink
test(google): add oidc google multi-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Apr 5, 2022
1 parent 40f675a commit d2a7bd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/context/src/MultiAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useState} from 'react';
import {OidcProvider, useOidc, useOidcAccessToken} from "./oidc";
import { configurationIdentityServer} from "./configurations";
import { configurationIdentityServer, configurationGoogle} from "./configurations";

const MultiAuth = ( {configurationName, handleConfigurationChange }) => {
const { login, logout, isAuthenticated} = useOidc(configurationName);
Expand All @@ -14,6 +14,7 @@ const MultiAuth = ( {configurationName, handleConfigurationChange }) => {
<select value={configurationName} onChange={handleConfigurationChange} >
<option value="config_1">config_1</option>
<option value="config_2">config_2</option>
<option value="google">google</option>
</select>
{!isAuthenticated && <button type="button" className="btn btn-primary" onClick={() => login()}>Login</button>}
{isAuthenticated && <button type="button" className="btn btn-primary" onClick={logout}>logout</button>}
Expand All @@ -40,7 +41,8 @@ export const MultiAuthContainer = () => {
config_2: {...configurationIdentityServer,
redirect_uri:callBack,
silent_redirect_uri: "",
scope: 'openid profile email api'}
scope: 'openid profile email api'},
google: { ...configurationGoogle }
}
const handleConfigurationChange = (event) => {
const configurationName = event.target.value;
Expand All @@ -67,7 +69,7 @@ const DisplayAccessToken = ({configurationName}) => {
<div className="card-body">
<h5 className="card-title">Access Token</h5>
<p style={{color:'red', "backgroundColor": 'white'}}>Please consider to configure the ServiceWorker in order to protect your application from XSRF attacks. "access_token" and "refresh_token" will never be accessible from your client side javascript.</p>
{accessToken != null && <p className="card-text">Access Token: {JSON.stringify(accessToken)}</p>}
{<p className="card-text">Access Token: {JSON.stringify(accessToken)}</p>}
{accessTokenPayload != null && <p className="card-text">Access Token Payload: {JSON.stringify(accessTokenPayload)}</p>}
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions packages/context/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ export const configurationAuth0 = {
service_worker_only: false,
};



export const configurationGoogle = {
client_id: '908893276222-f2drloh56ll0g99md38lv2k810d0nk0p.apps.googleusercontent.com',
redirect_uri: `${window.location.origin}/multi-auth/callback-google`,
scope: 'openid profile',
authority: 'https://accounts.google.com/',
service_worker_relative_url:'/OidcServiceWorker.js',
service_worker_only: false,
};

0 comments on commit d2a7bd6

Please sign in to comment.