Refactor igx-ts side-nav-auth template to standalone components and angular-auth-oidc-client v21#1554
Conversation
…t v15 API Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
|
@copilot Remove the -module.ts files and update the template to use standalone structure without breaking the logic |
…andalone structure Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
Done in commit Removed all NgModule files:
|
@copilot The standalone: true is not needed anymore. In user.service you should handle the case when storedUser is "undefined" |
… string in UserService Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
Done in commit
|
| AuthModule.forRoot({ config: [] }) | ||
| ), | ||
| provideAnimations(), | ||
| ExternalAuthService | ||
| provideHttpClient(withInterceptorsFromDi()), | ||
| { provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true }, | ||
| // TODO: DELETE THIS BEFORE PRODUCTION! | ||
| BackendProvider |
There was a problem hiding this comment.
@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 config
There was a problem hiding this comment.
Done in commit 4582360. Created authentication/provide-authentication.ts with a provideAuthentication() function that encapsulates all auth-related providers (OIDC AuthModule, HTTP client with interceptors, JWT interceptor, fake backend). app.config.ts now simply spreads ...provideAuthentication(), keeping the auth setup self-contained.
…ntained Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
6b61921 to
8355531
Compare
|
@copilot Refactor the authentication setup so that provideAuth can receive its configuration from an external source instead of being hardcoded. The idea is to store different provider settings (Google, Microsoft, etc.) in a separate file and pass them in as options when initializing authentication. This makes the setup flexible, reusable, and easier to maintain across environments. |
…accepts configs param Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/cb3cf6b1-325c-4b2e-bbab-f45bec906dd6 Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
Done in commit
To activate Google login, a developer simply edits |
|
@copilot Move the injected logic for adding the third-party providers from the app.ts to the new oidc-config and provide-authentication |
…ion() via ENVIRONMENT_INITIALIZER Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/b9a5e15c-6a51-4921-95a9-c1b3619358b8 Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
Done in commit
|
| { 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 } } |
There was a problem hiding this comment.
Would be neater if those are exported by the main auth barrel as something like AUTH_ROUTES for example and maybe registered in the app as children of
path: 'auth',
children: AUTH_ROUTES
There was a problem hiding this comment.
Done in commit 842d26e. Created authentication/auth.routes.ts that exports AUTH_ROUTES (profile + all redirect routes). In app.routes.ts they are now registered as { path: AUTH_BASE_PATH, children: AUTH_ROUTES }, so all auth callback and profile URLs live under /auth/....
| ), | ||
| provideAnimations(), | ||
| ExternalAuth | ||
| provideAuthentication(oidcConfigs) |
There was a problem hiding this comment.
If that's just imported to be passed down, it really doesn't do much. Would much rather have those tucked away behind the provide call if nothing is meant to be changed here by the user.
There was a problem hiding this comment.
Done in commit 842d26e. oidcConfigs is no longer imported or passed from app.config.ts — OIDC configuration is now fully encapsulated inside provideAuthentication().
| // externalAuth.addGoogle(); | ||
| // externalAuth.addMicrosoft(); | ||
| // externalAuth.addFacebook('YOUR_FACEBOOK_CLIENT_ID'); |
There was a problem hiding this comment.
Oh, that doesn't work quite like it used to. The old idea was to have this be the only modification point the user needs to apply without really touching anything under the auth folder, but I suppose that's not critical. Just saying, I'd move those into the provide call and have them trigger the respective full configs when passed in
There was a problem hiding this comment.
Done in commit 842d26e. provideAuthentication() now accepts a typed AuthProviders object with optional google, microsoft, and facebook credential entries. When a provider is supplied, both the OIDC config and the addGoogle/addMicrosoft/addFacebook call are triggered automatically — the user only needs to uncomment one line in app.config.ts.
| // googleOidcConfig, | ||
| // microsoftOidcConfig |
There was a problem hiding this comment.
Okay, that's odd too, so you need to uncomment in two places?
See previous comment on provide I guess
There was a problem hiding this comment.
oidc-configs.ts has been deleted. The configuration now lives entirely in provideAuthentication() — uncommenting one entry in app.config.ts is the only step needed to enable a provider.
|
@copilot Fix the latest comments |
… remove oidc-configs.ts Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/44c3c270-1ff0-4066-a825-2dc9656a47a6 Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
Done in commit |
standalone: truefromProfileandRedirectstoredUser === "undefined"string inUserServiceconstructor; wrapJSON.parsein try/catch to guard against malformed localStorage valuesprovideAuthentication()BaseOidcProviderto acceptconfigId: stringonly;ExternalAuthConfigstripped of dead OIDC-specific fields — now only holdsclient_idandredirect_url(used byFacebookProvider)Redirectreadsdata['provider']directly;ngOnInithas try/catch error handlingOidcConfigLoader;addGoogle()/addMicrosoft()no longer accept unusedclientIDparameterAUTH_ROUTESand exported from the authentication barrel; registered inapp.routes.tsas children of{ path: 'auth', children: AUTH_ROUTES }provideAuthentication()now accepts a typedAuthProvidersobject ({ google?, microsoft?, facebook? }); builds OIDC configs and registers social providers automatically —app.config.tsis the single modification point for enabling providers, no other file needs to changeoidc-configs.ts; OIDC configuration is now built insideprovideAuthentication()based on the credentials passed in, eliminating the need to uncomment in multiple placesaddGoogle(),addMicrosoft(),addFacebook()) fromAppconstructor into anENVIRONMENT_INITIALIZERinsideprovideAuthentication();Appno longer injectsExternalAuthproviders.spec.ts,services.spec.ts,redirect.spec.ts,login-bar.spec.ts,login.spec.ts,register.spec.ts)angular-auth-oidc-clientfrom~15.0.4to~21.0.1(latest stable); replaceimportProvidersFrom(AuthModule.forRoot(...))withprovideAuth(...)inprovide-authentication.ts; subscribe to theObservable<unknown>returned bylogoff()inBaseOidcProvider<issue_title>Refactor side navigation + authentication igx-ts template</issue_title>
Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.