Why am I seeing duplicate Scopes on IdentityServer4's consent screen? -
i writing identityserver4 implementation , using quickstart project described here.
when define apiresource (using inmemory classes now) looks identityserver creates scope same name resource. example
public static ienumerable<apiresource> getapiresources() { return new list<apiresource> { new apiresource("api", "my api") }; }
will create scope called "api" (this done in apiresource constructor). if add "api" allowed scope on client object (using inmemoryclients proof of concept) , request api scope in scope query string parameter in auth request javascript client invalid_scope error message.
i found following this documentation can add scopes apiresource through scopes property so
new apiresource { name = "api", displayname = "custom api", scopes = new list<scope> { new scope("api.read"), new scope("api.write") } }
so if instead define apiresource , request scopes api.read , api.write (and add them allowedscopes property on client object) works fine except consent page shows duplicate scopes. shows api.read 2 times , api.write 2 times. see consent screen here
the client configuration follows:
new client { clientid = "client.implicit", clientname = "javascript client", allowedgranttypes = granttypes.implicit, allowaccesstokensviabrowser = true, redirecturis = { "http://localhost:3000/health-check" }, postlogoutredirecturis = { "http://localhost:3000" }, allowedcorsorigins = { "http://localhost:3000" }, allowedscopes = { identityserverconstants.standardscopes.openid, identityserverconstants.standardscopes.profile, "customapi.read", "customapi.write" } }
why happening? doing wrong?
update: here portion of discovery document shows scopes listed once...
it looks problem quickstart ui... or scope.cs
class depending on how @ it. specifically, in method , line shown in class consentservice.cs
the following code
vm.resourcescopes = resources.apiresources.selectmany(x => x.scopes).select(x => createscopeviewmodel(x, vm.scopesconsented.contains(x.name) || model == null)).toarray();
is not filtering out duplicates. is, if 2 scopes have same name not considered equal. if gethashcode
, equals
overridden in scope.cs
(which in identityserver4 - not quickstart) solve problem. in case selectmany return unique set. because apiresources property implemented hashset. alternatively, write own logic make return unique set of scopes. how solved problem. wrote similar jon skeet's answer in this post filtered out duplicate scopes.
Comments
Post a Comment