damienbod / angular-auth-oidc-client

npm package for OpenID Connect, OAuth Code Flow with PKCE, Refresh tokens, Implicit Flow
https://www.npmjs.com/package/angular-auth-oidc-client
MIT License
1.15k stars 434 forks source link

[Question]: Angular 17 with SSR (Universal) #1898

Open m-prolic opened 9 months ago

m-prolic commented 9 months ago

What Version of the library are you using? 17.0.0

Angular version: 17.1.2

provideRouter( routesAuth,withPreloading(PreloadAllModules), withInMemoryScrolling({ scrollPositionRestoration: 'enabled' }), withEnabledBlockingInitialNavigation() ), provideAuth(authConfig), { provide: AbstractSecurityStorage, useClass: LocalStorage }, provideHttpClient(withFetch(), withInterceptors([authInterceptor(), agoraLoadingInterceptor])), .....

export const authConfig: PassedInitialConfig = { config: { triggerAuthorizationResultEvent: true, postLoginRoute: '/home', forbiddenRoute: '/forbidden', unauthorizedRoute: '/unauthorized', logLevel: LogLevel.Debug, historyCleanupOff: true, authority: 'https://demo.duendesoftware.com/', redirectUrl: 'http://localhost:4200/', postLogoutRedirectUri: 'http://localhost:4200/', clientId: 'interactive.public', scope: 'openid profile email api offline_access', responseType: 'code' }, }; We are using Authorization Code + PKCE - Duende identity server

Question

Does the library support Angular 17 with SSR ?

I am getting the next errors in the SERVER console:

image

image

Is it possible to get pages authorized/guarded rendered in SSR?

I've tried to implement Cookie Storage and provide it to app.config.server.json, but I am still getting messages that Storage is falsy/undefiend.

` const serverConfig: ApplicationConfig = { providers: [provideServerRendering(), provideHttpClient(), { provide: LocalStorage, useClass: ServerStorage }], };

export const config = mergeApplicationConfig(appConfig, serverConfig); `

Desnoo commented 6 months ago

The first issue seems related to this Code https://github.com/damienbod/angular-auth-oidc-client/blob/main/projects/angular-auth-oidc-client/src/lib/utils/crypto/crypto.service.ts

It seems like the angular domino browser (server side) has no crypto property. This only happens on the server side.