Skip to content

Solid-client-authn-browser silent authentication is not granted refresh_token  #1058

Open

Description

@josephguillaume

The intended behaviour with restorePreviousSession is to receive an access_token (default ttl 60min) and a refresh_token (ttl 24h) with prompt=none rather than prompt=consent.

As discussed at #909, deviating from prompt=consent is not entirely consistent with the OIDC spec. However, requiring prompt=consent means that consent is required at every page refresh, and not providing a refresh_token means that authorised operations are not possible after 60min without repeating authentication and consent again.

At the moment it seems the intention of CSS is to assume consent if the user has selected "remember", and the UI implies that the user will not need to provide consent again for some unspecified time/a number of future authentications.

https://github.com/solid/community-server/blob/4da1b1cc7df15f32abeacf6f7a8b0d677225e9ef/src/identity/interaction/util/InteractionCompleter.ts#L40

However, rejectedScopes does not accept offline_access when shouldRemember is true, it merely avoids rejecting it.
Removal of the offline_access scope occurs at
https://github.com/panva/node-oidc-provider/blob/d7a5ba5ba191d5af8e4bed9449cbb43a3d5a1619/lib/actions/authorization/check_scope.js#L34

This can be tested with a token request with scope="openid offline_access" and prompt=none, as is issued by solid-client-authn-browser when refreshing a logged in page with restorePreviousSession=true. Refresh_token is not provided in the response.

As discussed at https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#refresh-tokens and https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#issuerefreshtoken this behaviour can be changed by overriding the issueRefreshToken function in the config:
https://github.com/solid/community-server/blob/a1579f625a68ac97096ed476a55075a748258453/src/identity/configuration/IdentityProviderFactory.ts#L136
However, it's not clear to me how the "remember" status would be accessed from this function.
The following function obviously returns a refresh token for every token request:

async function issueRefreshToken(ctx, client, code) {
  if (!client.grantTypeAllowed('refresh_token')) {                     
return false;                                                    
}
  return true;                                                     
}                                                                  
config.issueRefreshToken=issueRefreshToken;

A workaround is to keep the default restorePreviousSession=false, so consent is requested every time and the refresh_token is consistently issued.

Activity

  1. jvherweg commented on Nov 12, 2021

    @jvherweg
    Member

    Thanks for the in-depth report.

    I would have too look deeper into this, but what I'm already wondering now is why the authn client is sending that request with no prompt? The first request should have provided a refresh token that can be used after that right, which can then be used.

    Since the OIDC spec explicitly says that the consent prompt needs to be present why is the authn client trying to go against that?

    Note that I'm not an OIDC expert so these are genuine questions why this is needed.

    We could indeed modify that functions, but the OIDC library is written to strictly follow the spec, so we would need a good reason to go against that.

  2. josephguillaume commented on Nov 12, 2021

    @josephguillaume
    Author

    The first request should have provided a refresh token that can be used after that right, which can then be used.

    In the browser, localStorage is considered insecure, so the refresh token is not stored there. So at the moment the refresh token does not survive a page refresh and needs to be re-requested...

    I'm definitely not an expert on security but the combination of solid-client-authn-browser's restorePreviousSession and CSS's adherence to the OIDC spec appears to be secure but broken at the moment :-)

    Someone who works on solid-client-authn-browser would probably be better placed to comment on whether a CSS solution is needed or whether we should wait for another solution to this problem.

    Should I take your comment to mean that the existing line with input.shouldRemember wasn't intended to allow the refresh token to be issued without further prompt=consent?

  3. jvherweg commented on Nov 12, 2021

    @jvherweg
    Member

    Should I take your comment to mean that the existing line with input.shouldRemember wasn't intended to allow the refresh token to be issued without further prompt=consent?

    The intent was to have refresh tokens. Whether that is with the prompt or not is mostly a consequence of the OIDC spec and the library. It's not that there was a strong opinion about needing this prompt or not (mostly because I only discovered later that this made a difference), but I would prefer not going against the OIDC spec unless it is really important and this behaviour is described in the Solid-OIDC spec.

  4. matthieubosquet commented on Nov 12, 2021

    @matthieubosquet
    Contributor

    I'm definitely not an expert on security but the combination of solid-client-authn-browser's restorePreviousSession and CSS's adherence to the OIDC spec appears to be secure but broken at the moment :-)

    Someone who works on solid-client-authn-browser would probably be better placed to comment on whether a CSS solution is needed or whether we should wait for another solution to this problem.

    @NSeydoux do you have an opinion on this?

  5. acoburn commented on Nov 12, 2021

    @acoburn
    Contributor

    The Solid-OIDC spec takes no special position on the prompt parameter, so the guidance would be to follow the OpenID specification. That text describing prompt=consent is:

    The Authorization Server SHOULD prompt the End-User for consent before returning information to the Client. If it cannot obtain consent, it MUST return an error, typically consent_required.

  6. josephguillaume commented on Nov 16, 2021

    @josephguillaume
    Author

    Just a short addition to say that the config.issueRefreshToken solution doesn't seem to be working for me after all.

    The token request is sent with body:
    "grant_type=refresh_token&refresh_token=REFRESH_TOKEN&scope=openid+offline_access",
    It gets rejected by node-oidc-provider with error:
    {"error":"invalid_scope","error_description":"refresh token missing requested scope","scope":"offline_access"}

    It looks like this is because offline_access was stripped from the refresh_token scopes when it was granted because prompt=consent was missing, and config.issueRefreshToken doesn't address this, i.e. it might be a bug in how node-oidc-provider has tackled this whole issue.

    My current workaround is to use a local-first approach for my app, caching all local data, and then refreshing the page whenever I get an authentication error... That's still easier than having to click on the consent button at every refresh.

    Edit: It looks like the OpenID spec doesn't require offline_access in the scope of a refresh_token request (presumably because it is implied by having a refresh token in the first place), so deleting offline_access from the solid-client-authn-browser request fixes the issue, i.e. I do again have a working setup by using config.issueRefreshToken and a modified solid-client-authn-browser.

  7. NSeydoux commented on Nov 19, 2021

    @NSeydoux

    The interpretation I have of the OpenID spec in the matter, which may be a bit far-fetched but sounds technically correct, is that the user must be prompted at least the first time, when no cookie is present. The presence of a cookie indicates that a session is active, and that the user has consented to the scopes requested by the app, therefore prompting the user again is not required. We made this assumption because as it stands, it is the only way we have found to be able to keep a long-running session in the browser in a secure way: iframe-based silent authentication is prevented by browsers security policies disabling cookies being shared with an iframe, and storing the refresh token in the local storage is as bad as storing the access token there.

    Edit: It looks like the OpenID spec doesn't require offline_access in the scope of a refresh_token request (presumably because it is implied by having a refresh token in the first place), so deleting offline_access from the solid-client-authn-browser request fixes the issue, i.e. I do again have a working setup by using config.issueRefreshToken and a modified solid-client-authn-browser.

    Right, but that's only going to work once I think: if I understand correctly, this uses the refresh token to get a new access token. That's well and good, but not including the offline_access scope in that request means that the OIDC provider does not return a new refresh token with the refreshed access token. When that access token expires, the problem of the session going stale remains. I'll double-check that my understanding true though.

  8. RubenVerborgh commented on Nov 22, 2021

    @RubenVerborgh
    Member

    @joachimvh Do we have enough information here to implement a solution?

  9. jvherweg commented on Nov 23, 2021

    @jvherweg
    Member

    @joachimvh Do we have enough information here to implement a solution?

    No. As in, we could certainly create a solution here or find a workaround, with either cookies or being more permissive. But what is not clear yet is if that would be the correct thing to do or if that would go against the OIDC spec.

    I wonder how/if ESS handles this. Are refresh tokens granted there if there is no prompt, do they use cookies, or does this also not work there?

  10. josephguillaume commented on Nov 27, 2021

    @josephguillaume
    Author

    That's well and good, but not including the offline_access scope in that request means that the OIDC provider does not return a new refresh token with the refreshed access token.

    That's not what node-oidc-provider does, so if that's the correct behaviour, this issue would need to be escalated to node-oidc-provider. The current implementation does this:

    1. Strip offline_access from scopes if consent!= prompt
      https://github.com/panva/node-oidc-provider/blob/d7a5ba5ba191d5af8e4bed9449cbb43a3d5a1619/lib/actions/authorization/check_scope.js#L34

    2. Allow the config to still issue a refresh_token when the user defined function issuerefreshtoken returns true
      https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#issuerefreshtoken

    3. Reject a grant_type=refresh_token request if offline_access is requested, because it was stripped from scopes in step 1
      https://github.com/panva/node-oidc-provider/blob/8d7116bd0e8d369e6133ee1b9004e706167335f5/lib/actions/grants/refresh_token.js#L82

    4. Include a new refresh_token with grant_type=refresh_token as long as the refresh token was valid
      https://github.com/panva/node-oidc-provider/blob/8d7116bd0e8d369e6133ee1b9004e706167335f5/lib/actions/grants/refresh_token.js#L130

    I.e. this behaviour is entirely controlled by node-oidc-provider, so it's a question of whether solid-client-authn-browser is wrong to ask for offline_access scope with consent=none, or node-oidc-provider is wrong to issue a new refresh_token for grant_type=refresh_token without offline_access being present in the request - and to reject a request with offline_access if it it's not in the granted scopes.

  11. josephguillaume commented on Nov 27, 2021

    @josephguillaume
    Author

    do they use cookies

    It's worth noting that node-oidc-provider already uses cookies. The user is always asked for consent if an existing session does not exist, and the session is passed as a cookie to the IDP.

    I don't think it would make sense to add an additional cookie mechanism. If CSS implements a separate solution (i.e. beyond issueRefreshToken) it would be because it disagrees with how node-oidc-provider is handling this issue.

  12. josephguillaume commented on Nov 27, 2021

    @josephguillaume
    Author

    I wonder how/if ESS handles this. Are refresh tokens granted there if there is no prompt, do they use cookies, or does this also not work there?

    I've now tried this on pod.inrupt.com using the solid pane tester, i.e. with "@inrupt/solid-client-authn-browser": "^1.11.2" and restorePreviousSession: true

    On refresh of the page, /authorization is sent:

    client_id: s23gKYjGj1CwGSEkPDpw5AUFWdV4gmJI
    redirect_uri: http://localhost:9000/
    response_type: code
    scope: openid offline_access
    state: 89fa4bde71ce4c40a62004aa0ccd8def
    code_challenge: x0Yn1z-5USY55DJUGxnLyIpMMRXNyFDsOIDAA_BYBR4
    code_challenge_method: S256
    prompt: none
    response_mode: query
    

    with cookies named ajs_group_id, ajs_anonymous_id, q_session, XSRF-TOKEN, and cognito

    The response is a 303 to https://broker.pod.inrupt.com/openid, setting and then sending a cookie:
    openid-session=wSo50C5iWuKkDWQRq5juik26h7iVVuwd;Version=1;Max-Age=300;Secure;HttpOnly;Secure;SameSite=none

    This redirects 303 without a consent screen to the redirect_uri with code and state in the query parameters

    The subsequent call to /token sends:

    grant_type: authorization_code
    redirect_uri: http://localhost:9000/
    code: CODE
    code_verifier: CODE_VERIFIER
    client_id: s23gKYjGj1CwGSEkPDpw5AUFWdV4gmJI
    

    and receives:

    access_token: "ACCESS_TOKEN"
    expires_in: 1861
    id_token: "ID_TOKEN"
    refresh_token: "REFRESH_TOKEN"
    token_type: "DPoP"
    

    In short, yes, ESS does issue a refresh_token with prompt: none and it uses cookies on the IDP (broker.pod.inrupt.com) to recognise an existing session.

    I also tried refreshing with Inrupt PodBrowser but it doesn't request offline_access or receive a refresh_token. The app just logs out after 30min.

    Edit: And as expected some time later, a request to /token with

    grant_type: refresh_token
    refresh_token: n9GwAhvLPjsYcwEVLnp1KbaXUjvX3TyS
    scope: openid offline_access
    

    returning

    access_token: "ACCESS_TOKEN"
    expires_in: 1861
    id_token: "ID_TOKEN"
    refresh_token: "REFRESH_TOKEN"
    token_type: "DPoP"
    
  13. woutermont commented on Nov 29, 2021

    @woutermont
    Contributor

    not providing a refresh_token means that authorised operations are not possible after 60min without repeating authentication and consent again.

    @josephguillaume can you clarify how you come by that time limit? As far as I know, prompt=none requests can succeed up to a much longer time, solely depending on the provider's cookies.

    The OIDC spec also mentions that "[t]he use of Refresh Tokens is not exclusive to the offline_access use case. The Authorization Server MAY grant Refresh Tokens in other contexts that are beyond the scope of this specification." Maybe the authorization panel can

    • look into adding a directive to include refresh tokens for the solid scope, or
    • (alternatively) make clear that the way the Inrupt client library currently combine prompt=none with refresh tokens is not the way to go?
  14. josephguillaume commented on Nov 29, 2021

    @josephguillaume
    Author

    The default ttl for an access token is 60min
    https://github.com/solid/community-server/blob/5a01f09f814f81b50d0372d9efad710fe5fd0460/config/identity/handler/provider-factory/identity.json#L42

    I have also experienced requests being rejected because the access token has expired, i.e. solid-client-authn-browser did not succeed in replacing it.

    Yes, solid-client-authn-browser does look like it has some code that can do a prompt=none request in an iframe, but I haven't worked out how to use it - the default definitely is using refresh tokens.

    And yes, a page refresh will also refresh the access token with prompt=none, though that's not really a solution.
    Incidentally at the moment consent is needed again after 60min even with a page refresh, but that's just because the default ttl of an idtoken is also 60min, i.e. solid-client-authn-browser fails to load the user details from localStorage because the idtoken has expired.
    https://github.com/solid/community-server/blob/5a01f09f814f81b50d0372d9efad710fe5fd0460/config/identity/handler/provider-factory/identity.json#L45
    Whether to lengthen the default on that is a separate issue. I've set it to 24h on my pod.

    Edit: expiry of the idtoken is no longer relevant as solid-client-authn-browser no longer uses the idtoken for restorePreviousSession inrupt/solid-client-authn-js@f0b715c

  15. jaxoncreed commented on Jul 30, 2024

    @jaxoncreed
    Contributor

    I'd like to reopen this issue, as having a refresh token after silent authentication would be very useful. Users expect an app to stay logged in for more than an hour even after a page refresh.

    In 2024 what are the barriers to this?

    P.S. I set up a little app that lets you test CSS tokens with a 30 second ttl to confirm that this behavior still happens and it does. Refreshing the token works during the initial login, but fail after you reload the page and go through silent login.

  16. josephguillaume commented on Sep 8, 2024

    @josephguillaume
    Author

    I'm still using a solution in which I bypass node-oidc-provider's checks on my own pod.

    However, I'm increasingly convinced that the solution is actually to store refresh tokens and use refresh token rotation.
    Auth0 now recommends this solution. Apparently they recommend tokens being stored in a web worker.
    https://auth0.com/docs/authenticate/login/configure-silent-authentication
    https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation

    In doing so, I'm aligning with node-oidc-provider's interpretation of the openid spec that consent is specifically needed each time offline access is requested.
    If refresh token rotation is in place, it is better to assume that a new refresh token can be granted based on a non-expired refresh token than on a session being active.
    My understanding is that the two differ in whether the evidence provided is a held token or a cookie associated with a pre-existing session. A rotated token is more like a one time password - with specific evidence of the right to receive a new refresh token. A session cookie is by definition being replayed and does not guarantee that the user wants this particular session to have offline access, e.g. if their intent was to be logged out of the client and reuse of the session was accidental.

    https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess
    "When offline access is requested, a prompt parameter value of consent MUST be used unless other conditions for processing the request permitting offline access to the requested resources are in place. The OP MUST always obtain consent to returning a Refresh Token that enables offline access to the requested resources. A previously saved user consent is not always sufficient to grant offline access."

    Edit: See BCP OAuth 2.0 for Browser-Based Applications https://www.ietf.org/archive/id/draft-ietf-oauth-browser-based-apps-19.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions