generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 918-rwd-menu
- Loading branch information
Showing
8 changed files
with
110 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { GrantTypes } from '@keycloak/keycloak-admin-client/lib/utils/auth'; | ||
|
||
export interface KeycloakCLIConfig { | ||
username: string; | ||
clientId: string; | ||
clientSecret: string; | ||
grantType: GrantTypes; | ||
} | ||
|
||
export interface KeycloakAdminConfig { | ||
username: string; | ||
password: string; | ||
clientId: string; | ||
grantType: GrantTypes; | ||
} | ||
|
||
export interface KeycloakConfig { | ||
target: string; | ||
realm: string; | ||
admin: KeycloakAdminConfig; | ||
cli: KeycloakCLIConfig; | ||
} | ||
|
||
export const config: KeycloakConfig = { | ||
target: process.env.SBL_PLAYWRIGHT_TEST_KC_TARGET ?? 'http://localhost:8880/', | ||
realm: process.env.SBL_PLAYWRIGHT_TEST_KC_REALM ?? 'regtech', | ||
admin: { | ||
username: process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_USERNAME ?? 'admin1', | ||
password: process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_PASSWORD ?? 'admin', | ||
clientId: | ||
process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_CLIENT_ID ?? 'regtech-client', | ||
grantType: (process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_GRANT_TYPE ?? | ||
'password') as GrantTypes, | ||
}, | ||
cli: { | ||
username: process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_USERNAME ?? 'admin', | ||
clientSecret: | ||
process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_SECRET ?? 'local_test_only', | ||
clientId: process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_ID ?? 'admin-cli', | ||
grantType: (process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_GRANT_TYPE ?? | ||
'client_credentials') as GrantTypes, | ||
}, | ||
}; |
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,23 +1,27 @@ | ||
import axios from 'axios'; | ||
import { config } from './authConstants'; | ||
|
||
export default async function getAdminKeycloakToken(): Promise<string> { | ||
const encodedParameters = new URLSearchParams(); | ||
encodedParameters.set('username', 'admin1'); | ||
encodedParameters.set('password', 'admin'); | ||
encodedParameters.set('grant_type', 'password'); | ||
encodedParameters.set('client_id', 'regtech-client'); | ||
encodedParameters.set('username', config.admin.username); | ||
encodedParameters.set('password', config.admin.password); | ||
encodedParameters.set('grant_type', config.admin.grantType); | ||
encodedParameters.set('client_id', config.admin.clientId); | ||
|
||
const optionsForGetAdminKeycloakToken = { | ||
method: 'POST', | ||
url: 'http://localhost:8880/realms/regtech/protocol/openid-connect/token', | ||
url: `${config.target}/realms/${config.realm}/protocol/openid-connect/token`, | ||
data: encodedParameters, | ||
}; | ||
try { | ||
const { data } = await axios.request(optionsForGetAdminKeycloakToken); | ||
return data.access_token as string; | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log('error when trying to fetch an admin token from keycloak :>> ', error); | ||
console.log( | ||
'error when trying to fetch an admin token from keycloak :>> ', | ||
error, | ||
); | ||
throw error; | ||
} | ||
} |
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