Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Keycloak] Use Proof Key for Code Exchange (PKCE) #1622

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions cypress/integration/filing/Filing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ describe("Filing", function() {
}).logEnv()

// Skip authentication on CI
if(!isCI(ENVIRONMENT)) {
cy.logout({ root: authUrl, realm: AUTH_REALM })
cy.login({
root: authUrl,
realm: AUTH_REALM,
client_id: AUTH_CLIENT_ID,
redirect_uri: HOST,
username: USERNAME,
password: PASSWORD
})
if (!isCI(ENVIRONMENT)) {
cy.hmdaLogin('filing', authUrl)
cy.url().should('contains', `${AUTH_BASE_URL}filing/`)
cy.url().should('contains', `/institutions`)
}

cy.viewport(1600, 900)
Expand Down
11 changes: 2 additions & 9 deletions cypress/integration/hmda-help/institution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,8 @@ describe('HMDA Help - Institutions', () => {
// Log in
if (!isCI(ENVIRONMENT)) {
cy.logout({ root: authUrl, realm: AUTH_REALM })
cy.wait(LOCAL_ACTION_DELAY)
cy.login({
root: authUrl,
realm: AUTH_REALM,
client_id: AUTH_CLIENT_ID,
redirect_uri: HOST,
username: USERNAME,
password: PASSWORD,
})
cy.hmdaLogin('hmda-help', authUrl)
cy.url().should('contains', `${AUTH_BASE_URL}hmda-help/`)
}

// Load site
Expand Down
10 changes: 2 additions & 8 deletions cypress/integration/hmda-help/publication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ describe('HMDA Help - Publications', () => {
if (!isCI(ENVIRONMENT)) {
cy.logout({ root: authUrl, realm: AUTH_REALM })
cy.wait(ACTION_DELAY)
cy.login({
root: authUrl,
realm: AUTH_REALM,
client_id: AUTH_CLIENT_ID,
redirect_uri: HOST,
username: USERNAME,
password: PASSWORD
})
cy.hmdaLogin('hmda-help', authUrl)
cy.url().should('contains', `${AUTH_BASE_URL}hmda-help/`)
}

// Load site
Expand Down
10 changes: 2 additions & 8 deletions cypress/integration/load/LargeFiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ describe('Large Filer', () => {
// Skip authentication on CI
if (!isCI(ENVIRONMENT)) {
cy.logout({ root: authUrl, realm: AUTH_REALM })
cy.login({
root: authUrl,
realm: AUTH_REALM,
client_id: AUTH_CLIENT_ID,
redirect_uri: HOST,
username: USERNAME,
password: PASSWORD,
})
cy.hmdaLogin('filing', authUrl)
cy.url().should('contains', `${AUTH_BASE_URL}filing/`)
}

cy.viewport(1600, 900)
Expand Down
13 changes: 13 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ Cypress.Commands.add("dataUrl", { prevSubject: true }, target => {
Cypress.Commands.add("logEnv", { prevSubject: true }, vars => {
logEnv(vars[0])
})

// Login via UI
Cypress.Commands.add('hmdaLogin', (app, authUrl) => {
const { USERNAME, PASSWORD, AUTH_BASE_URL, AUTH_REALM } = Cypress.env()
cy.logout({ root: authUrl, realm: AUTH_REALM })
cy.visit(`${AUTH_BASE_URL}${app}/`)

if (app.match('filing')) cy.get('button[title="Login"').click()

cy.get('#username').type(USERNAME)
cy.get('#password').type(PASSWORD)
cy.get('#kc-login').click()
})
2 changes: 1 addition & 1 deletion src/filing/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AppContainer extends Component {
this.redirectToReachablePeriod(filingPeriod)

const keycloak = initKeycloak()
keycloak.init().then(authenticated => {
keycloak.init({ pkceMethod: 'S256' }).then(authenticated => {
this.keycloakConfigured = true
if (authenticated) {
AccessToken.set(keycloak.token)
Expand Down
2 changes: 1 addition & 1 deletion src/hmda-help/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class App extends Component {
}

componentDidMount() {
keycloak.init().then(authenticated => {
keycloak.init({ pkceMethod: 'S256' }).then(authenticated => {
if (authenticated) {
AccessToken.set(keycloak.token)
refreshToken(this)
Expand Down