Repository navigation
Description
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.
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
jvherweg commentedon Nov 12, 2021
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.
josephguillaume commentedon Nov 12, 2021
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.shouldRememberwasn't intended to allow the refresh token to be issued without further prompt=consent?jvherweg commentedon Nov 12, 2021
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.
matthieubosquet commentedon Nov 12, 2021
@NSeydoux do you have an opinion on this?
acoburn commentedon Nov 12, 2021
The Solid-OIDC spec takes no special position on the
promptparameter, so the guidance would be to follow the OpenID specification. That text describingprompt=consentis:josephguillaume commentedon Nov 16, 2021
Just a short addition to say that the
config.issueRefreshTokensolution 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=consentwas missing, andconfig.issueRefreshTokendoesn'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.issueRefreshTokenand a modified solid-client-authn-browser.NSeydoux commentedon Nov 19, 2021
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.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_accessscope 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.RubenVerborgh commentedon Nov 22, 2021
@joachimvh Do we have enough information here to implement a solution?
jvherweg commentedon Nov 23, 2021
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?
josephguillaume commentedon Nov 27, 2021
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:
Strip offline_access from scopes if consent!= prompt
https://github.com/panva/node-oidc-provider/blob/d7a5ba5ba191d5af8e4bed9449cbb43a3d5a1619/lib/actions/authorization/check_scope.js#L34
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
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
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.
josephguillaume commentedon Nov 27, 2021
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.
josephguillaume commentedon Nov 27, 2021
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: trueOn refresh of the page, /authorization is sent:
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=noneThis redirects 303 without a consent screen to the redirect_uri with code and state in the query parameters
The subsequent call to /token sends:
and receives:
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
returning
woutermont commentedon Nov 29, 2021
@josephguillaume can you clarify how you come by that time limit? As far as I know,
prompt=nonerequests 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
solidscope, orprompt=nonewith refresh tokens is not the way to go?josephguillaume commentedon Nov 29, 2021
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
jaxoncreed commentedon Jul 30, 2024
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.
josephguillaume commentedon Sep 8, 2024
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
feat: prompt signin when session expires
feat: prompt sign-in when session expires (#173)