-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: keycloak support for auth service and provider
* refactor: add some new env-variables to the docker file * feat: support Helsinki-Profile Keycloak KK-1097 KK-1127. Use the `oidc-client-ts` for TypeScript instead of the `oidc-client` for JavaScript. Configure the login callback page to use the url_state instead of state for the next url handling. Configure the authService to support a (Helsinki-Profile) Keycloak. * refactor: update the silent_renew * refactor: use appconfig to config api tokens client * fix: reset auth state when auth token has expired * fix: app configuration should support current Tunnistamo by default * chore: add an env file example for a local use of test keycloak * docs: local keycloak usage * fix: fetchApiToken should have error handling * refactor: upgrade the silent renew html oidc-client
- Loading branch information
1 parent
3a8e9ff
commit edb6872
Showing
12 changed files
with
282 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
REACT_APP_OIDC_SERVER_TYPE=KEYCLOAK | ||
REACT_APP_OIDC_RETURN_TYPE="code" | ||
REACT_APP_OIDC_AUTHORITY=https://tunnistus.test.hel.ninja/auth/realms/helsinki-tunnistus/ | ||
REACT_APP_OIDC_CLIENT_ID="kukkuu-admin-ui-dev" | ||
REACT_APP_OIDC_KUKKUU_API_CLIENT_ID="kukkuu-api-dev" | ||
REACT_APP_OIDC_SCOPE="openid profile" | ||
REACT_APP_OIDC_AUDIENCES=kukkuu-api-dev | ||
# REACT_APP_API_URI=https://kukkuu.api.test.hel.ninja/graphql | ||
REACT_APP_API_URI=http://localhost:8081/graphql | ||
REACT_APP_SENTRY_DSN= | ||
REACT_APP_FEATURE_FLAG_EXTERNAL_TICKET_SYSTEM_SUPPORT=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head></head> | ||
<body> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.10.1/oidc-client.min.js"></script> | ||
<script> | ||
var mgr = new Oidc.UserManager(); | ||
mgr.signinSilentCallback().catch((error) => { | ||
console.error('silent_renew.html error', error); | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>Silent renewal</title> | ||
</head> | ||
|
||
<body> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client-ts/3.0.1/browser/oidc-client-ts.min.js" | ||
integrity="sha512-dbp16seDDFaTwxhmIRipIY43lyMA70TDsc0zBODkVoM2LmD+UI8ndMbW8Qospq5+st97jIiaGCg2/vl0lBDBqQ==" | ||
crossorigin="anonymous" referrerpolicy="no-referrer"></script> | ||
<script> | ||
var mgr = new oidc.UserManager({}); | ||
mgr.signinSilentCallback().catch(error => { | ||
console.error('silent_renew.html error', error); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
class AppConfig { | ||
static get apiUrl() { | ||
return getEnvOrError(process.env.REACT_APP_API_URI, 'REACT_APP_API_URI'); | ||
} | ||
|
||
static get oidcAuthority() { | ||
const origin = getEnvOrError( | ||
process.env.REACT_APP_OIDC_AUTHORITY, | ||
'REACT_APP_OIDC_AUTHORITY' | ||
); | ||
return new URL(origin).href; | ||
} | ||
|
||
/** | ||
* The audiences used in the OIDC. | ||
* | ||
* @example | ||
* // In Tunnistamo it can be left as undefined, | ||
* // because it is not included in the request done bythe OIDC client. | ||
* ["https://api.hel.fi/auth/kukkuu"] | ||
* // In Keycloak: | ||
* [ | ||
'kukkuu-api-test', | ||
'profile-api-test', | ||
] | ||
*/ | ||
static get oidcAudience() { | ||
return process.env.REACT_APP_OIDC_AUDIENCES; | ||
} | ||
|
||
static get oidcClientId() { | ||
return getEnvOrError( | ||
process.env.REACT_APP_OIDC_CLIENT_ID, | ||
'REACT_APP_OIDC_CLIENT_ID' | ||
); | ||
} | ||
|
||
static get oidcScope() { | ||
return getEnvOrError( | ||
process.env.REACT_APP_OIDC_SCOPE, | ||
'REACT_APP_OIDC_SCOPE,' | ||
); | ||
} | ||
|
||
static get oidcReturnType() { | ||
// "code" for authorization code flow. | ||
return process.env.REACT_APP_OIDC_RETURN_TYPE ?? 'code'; | ||
} | ||
|
||
static get oidcKukkuuApiClientId() { | ||
return ( | ||
process.env.REACT_APP_OIDC_KUKKUU_API_CLIENT_ID ?? this.oidcKukkuuAPIScope | ||
); | ||
} | ||
|
||
static get oidcKukkuuApiTokensUrl() { | ||
return this.oidcServerType === 'KEYCLOAK' | ||
? `${this.oidcAuthority}protocol/openid-connect/token` | ||
: `${this.oidcAuthority}api-tokens/`; | ||
} | ||
|
||
static get oidcKukkuuAPIScope() { | ||
return getEnvOrError( | ||
process.env.REACT_APP_KUKKUU_API_OIDC_SCOPE, | ||
'REACT_APP_KUKKUU_API_OIDC_SCOPE' | ||
); | ||
} | ||
|
||
/** | ||
* NOTE: The oidcServerType is not an OIDC client attribute. | ||
* It's purely used to help to select a configuration for the LoginProvider. | ||
* */ | ||
static get oidcServerType(): 'KEYCLOAK' | 'TUNNISTAMO' { | ||
const oidcServerType = | ||
process.env.REACT_APP_OIDC_SERVER_TYPE ?? 'TUNNISTAMO'; | ||
if (oidcServerType === 'KEYCLOAK' || oidcServerType === 'TUNNISTAMO') { | ||
return oidcServerType; | ||
} | ||
throw new Error(`Invalid OIDC server type: ${oidcServerType}`); | ||
} | ||
} | ||
|
||
// Accept both variable and name so that variable can be correctly replaced | ||
// by build. | ||
// process.env.VAR => value | ||
// process.env["VAR"] => no value | ||
// Name is used to make debugging easier. | ||
function getEnvOrError(variable?: string, name?: string) { | ||
if (!variable) { | ||
throw Error(`Environment variable with name ${name} was not found`); | ||
} | ||
return variable; | ||
} | ||
|
||
export default AppConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
src/domain/authentication/__tests__/__snapshots__/authService.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.