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

feat(auth): read saml auth enabled flag from portal context #558

Merged
merged 1 commit into from
Nov 21, 2024
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
15 changes: 13 additions & 2 deletions cypress/e2e/specs/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('Login Page', () => {
})

it('shows Login with SSO button', () => {
cy.mockPrivatePortal({ oidc_auth_enabled: true, basic_auth_enabled: false })
cy.mockPrivatePortal({ oidc_auth_enabled: true, basic_auth_enabled: false, saml_auth_enabled: false })

cy.visit('/', { useOriginalFn: true })
cy.location('pathname').should('equal', '/login')
Expand All @@ -225,8 +225,19 @@ describe('Login Page', () => {
cy.get('[data-testid="kong-auth-login-sso"]').should('exist')
})

it('shows Login with SSO button (SAML)', () => {
cy.mockPrivatePortal({ oidc_auth_enabled: false, basic_auth_enabled: false, saml_auth_enabled: true })

cy.visit('/', { useOriginalFn: true })
cy.location('pathname').should('equal', '/login')
cy.get('[data-testid="auth-form"]').should('be.visible')
cy.get('[data-testid="sign-up-encouragement-message"]').should('not.exist')
cy.get('[data-testid="kong-auth-login-sso"]').should('exist')
})


it('does not show Login with SSO button', () => {
cy.mockPrivatePortal({ oidc_auth_enabled: false })
cy.mockPrivatePortal({ oidc_auth_enabled: false, saml_auth_enabled: false })

cy.visit('/', { useOriginalFn: true })
cy.location('pathname').should('equal', '/login')
Expand Down
12 changes: 11 additions & 1 deletion cypress/e2e/specs/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ describe('Register Page', () => {
cy.get('[data-testid="kong-auth-login-sso"]').should('not.exist')
})
it('redirects to login (with SSO) when basic auth disabled', () => {
cy.mockPrivatePortal({ basic_auth_enabled: false, oidc_auth_enabled: true })
cy.mockPrivatePortal({ basic_auth_enabled: false, oidc_auth_enabled: true, saml_auth_enabled: false })

cy.visit('/', { useOriginalFn: true })
cy.location('pathname').should('equal', '/login')
cy.get('[data-testid="auth-form"]').should('be.visible')
cy.get('[data-testid="sign-up-encouragement-message"]').should('not.exist')
cy.get('[data-testid="kong-auth-login-sso"]').should('exist')
})

it('redirects to login (with SSO - SAML) when basic auth disabled', () => {
cy.mockPrivatePortal({ basic_auth_enabled: false, oidc_auth_enabled: false, saml_auth_enabled: true })

cy.visit('/', { useOriginalFn: true })
cy.location('pathname').should('equal', '/login')
Expand Down
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import useToaster from './composables/useToaster'
import usePortalApi from './hooks/usePortalApi'
import { createRedirectHandler } from './helpers/auth'
import portalAnalyticsBridge from '@kong-ui-public/portal-analytics-bridge'
import { PortalContext } from '@kong/sdk-portal-js'

/**
* Initialize application
Expand Down Expand Up @@ -66,18 +67,20 @@ async function init () {
featureset_id: featuresetId,
feature_set: featureSet,
oidc_auth_enabled: oidcAuthEnabled,
saml_auth_enabled: samlAuthEnabled,
is_public: isPublic,
basic_auth_enabled: basicAuthEnabled,
rbac_enabled: isRbacEnabled,
allowed_time_period: allowedTimePeriod,
canonical_domain: canonicalDomain
} = portalContext.data
} = portalContext.data as PortalContext & { saml_auth_enabled: boolean }

if (isPublic === false) {
portalApiV2.value.updateClientWithCredentials()
}

const authClientConfig = { basicAuthEnabled, oidcAuthEnabled }
// SAML Auth enabled comes on a different portal context property, but is handled the same as OIDC by the Auth Client
const authClientConfig = { basicAuthEnabled, oidcAuthEnabled: oidcAuthEnabled || samlAuthEnabled }

setPortalData({ portalId, orgId, authClientConfig, featuresetId, featureSet, isPublic, isRbacEnabled, allowedTimePeriod, canonicalDomain })
setSession(session)
Expand Down
Loading