Silent renew always fails with login_required

See original GitHub issue

I have a small sample based on the PKCE blog post and the accompanying project.

I can upload place the code somewhere for review, but the only changes are:

  1. I switched to using the NPM library.
  2. I removed the translation bits to yield a simpler demo.
  3. My secure files component only shows a piece of text, also to make it simpler.
  4. I’m reading the config values from a JSON files, not an extra web service. Again, for the sake of simplicity.

I’m connecting to an IdentityServer4 authority, which uses Azure AD to authenticate.

When I sign in, everything looks good and I’m authenticated, I get a token, and userinfo is called and returns sensible results.

Then I see the silent renew entries. They all look something like this:

onCheckSessionChanged
app.component.ts:36 ...recieved a check session event
angular-auth-oidc-client.js:337 silentRenewHeartBeatCheck
	silentRenewRunning: false
	idToken: true
	_userData.value: true
angular-auth-oidc-client.js:337 Token not expired?: 1580881666000 > 1580881646545  (true)
angular-auth-oidc-client.js:337 <iframe id=​"myiFrameForCheckSession" style=​"display:​ none;​">​…​</iframe>​
angular-auth-oidc-client.js:337 

Until the token expires:

...recieved a check session event
angular-auth-oidc-client.js:337 silentRenewHeartBeatCheck
	silentRenewRunning: false
	idToken: true
	_userData.value: true
angular-auth-oidc-client.js:337 Token not expired?: 1580881666000 > 1580881667564  (false)
angular-auth-oidc-client.js:337 IsAuthorized: id_token isTokenExpired, start silent renew if active
angular-auth-oidc-client.js:337 BEGIN refresh session Authorize
angular-auth-oidc-client.js:337 RefreshSession created. adding myautostate: 15808816675640.<Redacted>
angular-auth-oidc-client.js:337 startRenew for URL:https://<redacted>.azurewebsites.net/connect/authorize?client_id=MyClientID&redirect_uri=https%3A%2F%2Flocalhost%3A4200%2Fassets%2Fsilent-renew.html&response_type=code&scope=openid%20profile%20api1&nonce=N<Redacted>&state=<Redacted>&code_challenge=<Redacted>&code_challenge_method=S256&prompt=none
angular-auth-oidc-client.js:337 silentRenewEventHandler
app.component.ts:75 Auth result received AuthorizationState:unauthorized validationResult:LoginRequired
app.component.ts:81 

I redacted state, nonce and code and anything else I thought migh be sensitive, but they all look like I’d expect.

Notice that the silent renew sends prompt=none, which is what I expect. IdentityServer responds with login_required.

Looking at the IdentityServer logs, I see this for the intial (interactive) login:

IdentityServer4.Endpoints.AuthorizeCallbackEndpoint: ValidatedAuthorizeRequest
{
    "ClientId": "RegisteredClientID",
    "ClientName": "My App Name",
    "RedirectUri": "https://localhost:4200/auth-callback",
    "AllowedRedirectUris": [
        "https://localhost:4200/auth-callback",
        "https://localhost:4200",
        "https://localhost:4200/assets/silent-renew.html"
    ],
    "SubjectId": "253aa016-74ed-40dc-8b78-5aa5085a4df6",
    "ResponseType": "code",
    "ResponseMode": "query",
    "GrantType": "authorization_code",
    "RequestedScopes": "openid profile api1",
    "State": "<Redacted>",
    "Nonce": "N<Redacted>",
    "SessionId": "<Redacted>",
    "Raw": {
        "client_id": "RegisteredClientID",
        "redirect_uri": "https://localhost:4200/auth-callback",
        "response_type": "code",
        "scope": "openid profile api1",
        "nonce": "N<Redacted>",
        "state": "<Redacted>",
        "code_challenge": "<Redacted>",
        "code_challenge_method": "S256"
    }
}

The silent renew fails every time:

IdentityServer4.Endpoints.AuthorizeEndpoint: 
{
    "ClientId": "MyRegisteredClientID",
    "ClientName": "My App Name",
    "RedirectUri": "https://localhost:4200/assets/silent-renew.html",
    "AllowedRedirectUris": [
        "https://localhost:4200/auth-callback",
        "https://localhost:4200",
        "https://localhost:4200/assets/silent-renew.html"
    ],
    "SubjectId": "anonymous",
    "ResponseType": "code",
    "ResponseMode": "query",
    "GrantType": "authorization_code",
    "RequestedScopes": "openid profile Citadel.Auth",
    "State": "<Redacted>",
    "Nonce": "N<Redacted>",
    "PromptMode": "none",
    "Raw": {
        "client_id": "MyRegisteredClientID",
        "redirect_uri": "https://localhost:4200/assets/silent-renew.html",
        "response_type": "code",
        "scope": "openid profile Citadel.Auth",
        "nonce": "N<Redacted>",
        "state": "<Redacted>",
        "code_challenge": "<Redacted>",
        "code_challenge_method": "S256",
        "prompt": "none"
    }
}

This causes a Token Issued Failure error with login_required.

Note that it sends along the code, but not the subject, and not the session ID. This seems intuitively correct to me, as the session is expired (that’s why we’re renewing) and the code was issued to refresh the session, so it should surely imply the subject. But clearly my intuition is way off.

Here is the error showing the token issue failure:

IdentityServer4.Events.DefaultEventService: {
    "Name": "Token Issued Failure",
    "Category": "Token",
    "EventType": "Failure",
    "Id": 2001,
    "ClientId": "MyRegisteredClientID",
    "ClientName": "My App Name",
    "RedirectUri": "https://localhost:4200/assets/silent-renew.html",
    "Endpoint": "Authorize",
    "Scopes": "openid profile api1",
    "GrantType": "authorization_code",
    "Error": "login_required",
    "ActivityId": "80000980-0000-bc00-bf76-84710c7967bb",
    "TimeStamp": "2020-02-05T05:31:09Z",
    "ProcessId": 90786,
    "LocalIpAddress": "<Redacted>",
    "RemoteIpAddress": "<Redacted>"
}```


Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elmcherquicommented, May 9, 2021

Hello if anyone has the same issue with asp.net core here is what i ve done. I don’t recommand what i did in production, i’am still in the process of understanding and tightening the security. 1- Allow the cookie to be available ( Cross Site Request Forgey ) image

2- Allow the site to be available within iframe image

3- Make sur you are on the same browser and not in private mode . i made my angular app available through https so that it can run on another tab of the same chrome instance.

0reactions
gundogduhasancommented, Jun 9, 2022

I have the similar issue after adding the second client. I explain in here https://github.com/damienbod/angular-auth-oidc-client/issues/1413 My subject id also null like @CobusKruger

Read more comments on GitHub >

github_iconTop Results From Across the Web

Silent Renew and the "login_required" Error When Using oidc ...
The error we were getting back was "Error from signinSilent: login_required". This indicates that the user's session is no longer active on ......
Read more >
Failed silent Authentication - Login Required - Auth0 Community
Hi, I am developing single page application in reactjs. We are registering user with username/password given by Auth0 login page.
Read more >
IdentityServer/IdentityServer4 - Gitter
Silent renews cause a Token Issued Failure error with login_required , and I think that's because they don't supply the subject ID. This...
Read more >
CORS OAuth 2.0 response mode for silent prompt=none ...
CORS OAuth 2.0 response mode for silent prompt=none requests ... it will return a login_required , consent_required or interaction_required error.
Read more >
ASP.NET Core, C#, IdentityServer4, oidc-client - Silent Renew
Today we implement the ground work needed for silent refreshing of our tokens from our nuxtjs application using the oidc-client ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found