-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor igx-ts side-nav-auth template to standalone components and angular-auth-oidc-client v21 #1554
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
Open
Copilot
wants to merge
34
commits into
master
Choose a base branch
from
copilot/refactor-side-navigation-auth-template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor igx-ts side-nav-auth template to standalone components and angular-auth-oidc-client v21 #1554
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
eba1717
Initial plan
Copilot 9b17452
fix: migrate side-nav-auth igx-ts template to angular-auth-oidc-clien…
Copilot dcec8e5
fix(igx-ts): update the providers to fix build errors
Hristo313 740b8fe
refactor: remove NgModule files and convert side-nav-auth to fully st…
Copilot 2658cf5
fix: remove standalone: true decorators and guard against "undefined"…
Copilot 4582360
refactor: extract provideAuthentication() to keep auth config self-co…
Copilot 455460d
merge master
Hristo313 fbdbef8
Merge branch 'master' into copilot/refactor-side-navigation-auth-temp…
Hristo313 62e36c6
refactor: migrate spec files from Jasmine to Vitest syntax (vi.fn, vi…
Copilot 96e8c95
fix(igx-ts): fixing build tests errors
Hristo313 c4cb896
fix: sync formatUserData in providers, mock close/navigate spies in s…
Copilot 2252821
revert: undo c4cb896 provider/spec changes and restore yarn.lock
Copilot 2dd06a8
fix(igx-ts): fix failing tests
Hristo313 4eb4a78
Merge branch 'master' into copilot/refactor-side-navigation-auth-temp…
Hristo313 ac3f5e3
refactor: wire OIDC configs via OidcConfigLoader, fix route data shap…
Copilot b7697ea
fix(igx-ts): update spec files
Hristo313 97ac362
refactor: remove OidcConfigLoader, simplify ExternalAuth and provideA…
Copilot 67bf7be
chore: add TODO comments for OIDC clientID usage in addGoogle/addMicr…
Copilot e75af5c
fix: remove unused clientID params from addGoogle/addMicrosoft, drop …
Copilot 4f06d3f
fix(igx-ts): add home route
Hristo313 09f09f8
feat: restore social provider registration comments in App constructo…
Copilot 30cf341
fix: use clearer CLIENT_ID placeholder for Facebook provider
Copilot 7198fc6
fix(igx-ts): add clientId to microsoft and google login
Hristo313 8355531
fix(igx-ts): fix tests
Hristo313 ad5db64
fix(igx-ts): fix login
Hristo313 6d18c67
Merge branch 'master' into copilot/refactor-side-navigation-auth-temp…
Hristo313 1348032
fix(igx-ts): fix tests
Hristo313 3947cb4
fix(igx-ts): update the provide auth
Hristo313 e504f1f
Merge branch 'master' into copilot/refactor-side-navigation-auth-temp…
Hristo313 cf76d0d
Merge branch 'master' into copilot/refactor-side-navigation-auth-temp…
Hristo313 dcbf515
fix(igx-ts): fix configuration of multiple providers problem
Hristo313 24a7db3
Externalize OIDC configs to oidc-configs.ts; provideAuthentication() …
Copilot 658a2bd
fix(igx-ts): add fixes
Hristo313 6ba1589
Move social provider registration from app.ts into provideAuthenticat…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
48 changes: 0 additions & 48 deletions
48
packages/igx-templates/igx-ts/projects/side-nav-auth/files/src/app/app-module.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
12 changes: 11 additions & 1 deletion
12
packages/igx-templates/igx-ts/projects/side-nav-auth/files/src/app/app.routes.ts
This file contains hidden or 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,3 +1,13 @@ | ||
| import { Routes } from '@angular/router'; | ||
| import { AuthGuard } from './authentication/auth.guard'; | ||
| import { Profile } from './authentication/profile/profile'; | ||
| import { Redirect } from './authentication/redirect/redirect'; | ||
| import { ExternalAuthProvider } from './authentication/services/external-auth-configs'; | ||
| import { ExternalAuthRedirectUrl } from './authentication/services/external-auth.service'; | ||
|
|
||
| export const routes: Routes = []; | ||
| export const routes: Routes = [ | ||
| { path: 'profile', component: Profile, canActivate: [AuthGuard] }, | ||
| { path: ExternalAuthRedirectUrl.Google, component: Redirect, data: { provider: ExternalAuthProvider.Google } }, | ||
| { path: ExternalAuthRedirectUrl.Facebook, component: Redirect, data: { provider: ExternalAuthProvider.Facebook } }, | ||
| { path: ExternalAuthRedirectUrl.Microsoft, component: Redirect, data: { provider: ExternalAuthProvider.Microsoft } } | ||
Hristo313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ]; | ||
This file contains hidden or 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
13 changes: 0 additions & 13 deletions
13
.../igx-ts/projects/side-nav-auth/files/src/app/authentication/authentication-module.spec.ts
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
...lates/igx-ts/projects/side-nav-auth/files/src/app/authentication/authentication-module.ts
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
...x-ts/projects/side-nav-auth/files/src/app/authentication/authentication-routing-module.ts
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
packages/igx-templates/igx-ts/projects/side-nav-auth/files/src/app/authentication/index.ts
This file contains hidden or 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 hidden or 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 hidden or 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
1 change: 0 additions & 1 deletion
1
...tes/igx-ts/projects/side-nav-auth/files/src/app/authentication/providers/auth-provider.ts
This file contains hidden or 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
65 changes: 14 additions & 51 deletions
65
...gx-ts/projects/side-nav-auth/files/src/app/authentication/providers/base-oidc-provider.ts
This file contains hidden or 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,71 +1,34 @@ | ||
| import { | ||
| AuthWellKnownEndpoints, | ||
| OidcConfigService, | ||
| OidcSecurityService, | ||
| OpenIDImplicitFlowConfiguration | ||
| } from 'angular-auth-oidc-client'; | ||
| import { take } from 'rxjs/operators'; | ||
| import { OidcSecurityService } from 'angular-auth-oidc-client'; | ||
| import { firstValueFrom } from 'rxjs'; | ||
| import { ExternalLogin } from '../models/login'; | ||
| import { ExternalAuthConfig } from '../services/external-auth-configs'; | ||
| import { AuthProvider } from './auth-provider'; | ||
|
|
||
| /** Base provider for OpenID Connect (OIDC) https://openid.net/connect/ */ | ||
| export abstract class BaseOidcProvider implements AuthProvider { | ||
| constructor( | ||
| protected oidcConfigService: OidcConfigService, | ||
| protected oidcSecurityService: OidcSecurityService, | ||
| protected externalStsConfig: ExternalAuthConfig) { } | ||
|
|
||
| public config() { | ||
| const openIDImplicitFlowConfiguration = new OpenIDImplicitFlowConfiguration(); | ||
| openIDImplicitFlowConfiguration.stsServer = this.externalStsConfig.stsServer; | ||
| openIDImplicitFlowConfiguration.redirect_url = this.externalStsConfig.redirect_url; | ||
| openIDImplicitFlowConfiguration.client_id = this.externalStsConfig.client_id; | ||
| openIDImplicitFlowConfiguration.response_type = this.externalStsConfig.response_type; | ||
| openIDImplicitFlowConfiguration.scope = this.externalStsConfig.scope; | ||
| openIDImplicitFlowConfiguration.post_logout_redirect_uri = this.externalStsConfig.redirect_url; | ||
| openIDImplicitFlowConfiguration.post_login_route = this.externalStsConfig.post_login_route; | ||
| openIDImplicitFlowConfiguration.auto_userinfo = this.externalStsConfig.auto_userinfo; | ||
| openIDImplicitFlowConfiguration.max_id_token_iat_offset_allowed_in_seconds = | ||
| this.externalStsConfig.max_id_token_iat_offset_allowed_in_seconds; | ||
|
|
||
| const authWellKnownEndpoints = new AuthWellKnownEndpoints(); | ||
| authWellKnownEndpoints.setWellKnownEndpoints(this.oidcConfigService.wellKnownEndpoints); | ||
| this.oidcSecurityService.setupModule(openIDImplicitFlowConfiguration, authWellKnownEndpoints); | ||
| } | ||
|
|
||
| public login() { | ||
| this.oidcConfigService.onConfigurationLoaded.pipe(take(1)).subscribe(() => { | ||
| this.config(); | ||
| this.oidcSecurityService.authorize(); | ||
| }); | ||
| this.oidcConfigService.load_using_stsServer(this.externalStsConfig.stsServer); | ||
| this.oidcSecurityService.authorize(this.externalStsConfig.configId); | ||
| } | ||
|
|
||
| public getUserInfo(): Promise<ExternalLogin> { | ||
| let resolve: (val: ExternalLogin) => void; | ||
| let reject: () => void; | ||
| const user = new Promise<ExternalLogin>((res, rej) => { | ||
| resolve = res; | ||
| reject = rej; | ||
| }); | ||
| this.oidcConfigService.onConfigurationLoaded.pipe(take(1)).subscribe(() => { | ||
| this.config(); | ||
| this.oidcSecurityService.onAuthorizationResult.subscribe(() => { | ||
| this.oidcSecurityService.getUserData().subscribe(userData => { | ||
| resolve(this.formatUserData(userData)); | ||
| }); | ||
| }); | ||
| this.oidcSecurityService.authorizedImplicitFlowCallback(); | ||
| }); | ||
| this.oidcConfigService.load_using_stsServer(this.externalStsConfig.stsServer); | ||
| return user; | ||
| public async getUserInfo(): Promise<ExternalLogin> { | ||
| const result = await firstValueFrom(this.oidcSecurityService.userData$); | ||
| const configData = result.allUserData?.find( | ||
| d => d.configId === this.externalStsConfig.configId | ||
| ); | ||
| if (configData?.userData) { | ||
| return this.formatUserData(configData.userData); | ||
| } | ||
Hristo313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return Promise.reject(null); | ||
| } | ||
|
|
||
| public logout() { | ||
| this.oidcSecurityService.logoff(); | ||
| this.oidcSecurityService.logoff(this.externalStsConfig.configId); | ||
| } | ||
|
|
||
| /** Format received user data per provider claims */ | ||
| protected abstract formatUserData(userData: { [key: string]: any; }): ExternalLogin; | ||
| protected abstract formatUserData(userData: { [key: string]: any; }): Promise<ExternalLogin>; | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Don't move all of the previous config of AuthenticationModule into the main app config - it's job was to keep the authentication self-contained. Since we're not working with modules anymore, the modern approach for that would be to wrap the necessary config in something like
provideAuthetication()that can be added to the configThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit
4582360. Createdauthentication/provide-authentication.tswith aprovideAuthentication()function that encapsulates all auth-related providers (OIDCAuthModule, HTTP client with interceptors, JWT interceptor, fake backend).app.config.tsnow simply spreads...provideAuthentication(), keeping the auth setup self-contained.