IdentityServer / IdentityServer4

OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
https://identityserver.io
Apache License 2.0
9.22k stars 4.01k forks source link

PersistedGrants not being used #1406

Closed nixa333 closed 7 years ago

nixa333 commented 7 years ago

I've implemented IPersistedGrantStore, and defined a Client that has properties RequireConsent and AllowRememberConsent set to true. I've also removed offline access scope from that client as I've read somewhere that you always force Consent if offline access scope is requested, as per specification. When I go to the login screen the first time, I'm presented with consent view, click allow and remember my decision, I can see the record in DB table PersistedGrants being added with type user_consent. Next time I try to login, that record is fetched from database by my implementation of IPersistedGrantStore, but the consent view is still presented. If I then click allow again, DB throw an exception because IS is trying to insert another PersistedGrant record with the same key.

Did I overlook certain setting that would make it behave as expected? PS. I've implemented all major stores and everything is kept in SQL Server db, not using any of those InMemory stores.

nixa333 commented 7 years ago

After substantial amount of debugging, here's what the problem was: _ScopeListItem.cshtml from 6_AspNetIdentity sample, has this section of code @if (Model.Required) { input type="hidden" name="ScopesConsented" value="@Model.Name" /> } This is evidently rendered only if the scope is marked as required. Those scopes that are marked as Required are only ones that get posted to controller action. In my case I had a Client requesting OpenId and Profile as standard scopes, and also three scopes defined by my ApiResource. Admittedly I didn't mark the Api scopes as required, but the problem was also that the Profile scope wasn't required by default. So when saving the Consent, the Data property didn't contain Profile scope, and there was a mismatch of requested and consented scopes on all following login attempts, which triggered the Consent process.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.