oidc-client-ts icon indicating copy to clipboard operation
oidc-client-ts copied to clipboard

Change scope separators

Open b1ek opened this issue 2 years ago • 4 comments
trafficstars

Hey y'all. I am using this to log in to one server and the scope seems to be separated by commas instead of spaces. Is it possible to change scope separators? Thanks.

That's the error I get from the server:

The requested scope is invalid, unknown, or malformed. The OAuth 2.0 Client is not allowed to request scope 'openid,given_name,family_name'.

b1ek avatar May 16 '23 04:05 b1ek

Well, i investigated a little bit furter and found out that I should've set scope to a custom space-separated string, not an array, and if scope is an array, it transforms it into a (?) comma-separated string

Perhaps this should be fixed.

b1ek avatar May 16 '23 04:05 b1ek

scope is supported as an optional string parameter. See https://github.com/authts/oidc-client-ts/blob/89733f5db534f77acac47693a57758067dea2413/src/OidcClientSettings.ts#-L47-L48. After the spec https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest, multiple can be done like "s1 s2", aka spaces in between.

pamapa avatar May 16 '23 13:05 pamapa

scope is supported as an optional string parameter. See https://github.com/authts/oidc-client-ts/blob/89733f5db534f77acac47693a57758067dea2413/src/OidcClientSettings.ts#-L47-L48. After the spec https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest, multiple can be done like "s1 s2", aka spaces in between.

I know that they are separated by spaces (took me some time figuring it out, though), but if someone passes an array instead of string (js), it would be comma separated.

This is more of an enhancement discussion, since it can confuse those who are unfamiliar with OIDC (like me).

I suppose that there are two ways to solve this:

  1. Throw an exception if a non-string is passed: if (typeof(scope)) !== 'string' throw Error(...)
  2. Add array to accepted types in scope parameter, like: scope?: string | string[] and properly transform the array so it would be space separated: [...].join(' ')

b1ek avatar May 16 '23 16:05 b1ek

Ah, now i understand what you are about.

  1. Throw an exception if a non-string is passed

Currently the type is string | undefined, hence when using typescript you can not pass a string array, whiteout getting an error...

2. Add array to accepted type...

That could be a nice improvement, which makes using this library easier, feel free to add make a merge request which this. You can more or less copy/last the resource field, except the semicolon...

pamapa avatar May 17 '23 07:05 pamapa