Redirect after login
Hi! I have the such question: I have auth-guard, which is checking isAuthorized(); If no authorized, I save redirect_url in local storage, it's redirecting user to login page, user login, in the IDS we have redirect url to the '/callback'. In the AppRouting I have such entry: {path: '', redirectTo: 'dashboard', pathMatch: 'full'}, The question how app-routing and oidc client should be configured to redirect user to the page, that he has requested before? Ex. User enters http://localhost/jobs, unauthorized, login, redirecting to the dashboard (but I need redirect to jobs). There are some info in documentation about it, but it's not clear for me. Could you help?
@evoronovich I have docs for this in the API documentation
Where is his documented exactly? The authorize() function seems to use the static url from this.authConfiguration.redirect_url. The only thing I could think of is to pass an urlHandler to authorize() and rewrite the url but that seems hacky.
I will add a code exmample for this. This describes the event which can be used.
https://github.com/damienbod/angular-auth-oidc-client/blob/master/API_DOCUMENTATION.md#onauthorizationresult-observable
You should not use the guard on the default route. You need to save your path somewhere in localstorage or sessionstorage before the authorize request, and use this after in the event.
Thanks!
Hello, @damienbod, I cannot find any example for this. the url that you sent does not exist now. can you send it again. :) Thank you.
Hi @HedayatTajik The docs were moved and we didn't update this issue:
here's the new link:
https://nice-hill-002425310.azurestaticapps.net/docs/documentation/public-api
Greetings Damien
Thank you
Von: damienbod @.> Gesendet: Donnerstag, 15. Juli 2021 10:54 An: damienbod/angular-auth-oidc-client @.> Cc: Hedayat Tajik @.>; Comment @.> Betreff: Re: [damienbod/angular-auth-oidc-client] Redirect after login (#386)
The docs were moved, didn't update this issue:
https://nice-hill-002425310.azurestaticapps.net/docs/documentation/public-api
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/damienbod/angular-auth-oidc-client/issues/386#issuecomment-880520697, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQYQ66JT3S5VKYLHA5CWX5LTX2O4LANCNFSM4GU3W4HQ.
I'm having a similar problem. I'm using angular-auth-oidc-client 15.0.3.
export class AuthGuard implements CanActivate {
constructor(private oidcSecurityService: OidcSecurityService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.oidcSecurityService.checkAuth()
.pipe(map((response) => {
if (response?.isAuthenticated) return true;
const url = state.url;
this.oidcSecurityService.authorize(null, {redirectUrl: url});
return false;
}));
}
}
The authorization server is responding with 404 to the authorize request. The URL requested looks like this: `https://authority/oauth/authorize?client_id=xxx&redirect_uri=%2Fmypage&response_type=code&scope=openid%20profile%20email&...
If I hardcode the full url in the authorize call:
this.oidcSecurityService.authorize(null, {redirectUrl: 'https://mydomain/root_app_path/mypage'});`
I get the following error from the authority: "The specified 'redirect_uri' parameter doesn't match the client redirection endpoint the authorization code was initially sent to."
If I change the redirectUrl in the OpenIdConfiguration to hardcode my very page, then everything works:
export const OidcConfig: OpenIdConfiguration = {
// ...
redirectUrl: 'https://mydomain/root_app_path/mypage',
// ...
};
Do you have any pointers please?
Thanks.
Passing the redirect URI in the config is the recommended way because the IDP has to know all redirectUrls in prior, and he matches them. You have to implement the "when the IDP redirects to my app then I want to redirect to the route the user was before" by yourself or you can also try the "AutoLoginPartialRoutesGuard" from the lib.
Thanks for the quick reply. I incorrectly assumed that providing the redirectUrl in authorize() will actually do what AutoLoginPartialRoutesGuard does for me. For anyone else landing here, it's worth reading @FabianGosebrink's explanation here.
Thanks for linking the response. I should add this response to the docs :D Would have searched it as well. Thanks!