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

Obtaining new credentials with refresh code failed #725

Closed
Kayes-Islam opened this issue May 13, 2020 · 3 comments · Fixed by #731
Closed

Obtaining new credentials with refresh code failed #725

Kayes-Islam opened this issue May 13, 2020 · 3 comments · Fixed by #731

Comments

@Kayes-Islam
Copy link

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:
My configuration is:
oidcConfigService.withConfig({ stsServer: 'https://our-server.com/oauth', redirectUrl: window.location.origin, postLogoutRedirectUri: window.location.origin, clientId: 'our-app', scope: 'openid profile ourapi', responseType: 'code', silentRenew: true, useRefreshToken: true, logLevel: LogLevel.Debug });

We are using identity 4 server with one time only refresh token, below is the configuration:
image

Here's the browser log of failure:

IsAuthorized: id_token idTokenHasExpired, start silent renew if active
BEGIN refresh session Authorize
RefreshSession created. adding myautostate: _some_code_here_
found refresh code, obtaining new credentials with refresh code
POST https://beta-rest.oceaninformatics.com/oauth/connect/token 400 (Bad Request)

Looking at the browser's network tab the response to the "token" endpoint returned 404 with body: {"error":"invalid_grant"}

Interestingly, probably the source of the problem, the form data from from the request shows token as undefined. Here's the raw of the request form data form network tab:
grant_type=refresh_token&client_id=our-app&refresh_token=undefined

Expected behavior
Silent renew with refresh token should work as expected.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version 81.0.4044.129
@Kayes-Islam
Copy link
Author

Doing a bit more debug looks like there's an issue with AuthStateService.getRefreshToken():

        const token = this.storagePersistanceService.getRefreshToken();
        return decodeURIComponent(token);

If token is undefined decode turns it into a string "undefined". However, I'm still not sure why the refresh token is not there in authResult.

@Kayes-Islam
Copy link
Author

Looking at OpenID connect Core, the client must include offline_access scope. So I changed my configuration to include offline_access in the scope:
scope: 'openid profile ourapi offline_access'

This has fixed the issue on my side. However, I think AuthStateService.getRefreshToken() can be improved as per comment above and this card can be closed.

@damienbod
Copy link
Owner

Thanks for reporting, yes, you must request the offline_access scope. Maybe I will add a warning , because useRefreshToken requires this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants