Add custom scopes in CreateAuthURL via PKCEConfig#20
Add custom scopes in CreateAuthURL via PKCEConfig#20notable-franco wants to merge 2 commits intoonelogin:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables custom OAuth scopes when creating authorization URLs in the onelogin-node-sdk. Previously, the library hardcoded the openid scope with no mechanism to add additional scopes needed for custom application parameters.
Key Changes:
- Adds optional
scopesarray parameter toPKCEConfiginterface - Removes hardcoded
QUERYPARAM_SCOPEconstant - Constructs scope query parameter dynamically, appending custom scopes after required
openidscope
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let queryParams = [ | ||
| `code_challenge=${codeChallenge}`, `client_id=${clientID}`, `redirect_uri=${redirectURL}`, | ||
| QUERYPARAM_CODE_CHALLENGE_METHOD, QUERYPARAM_RESPONSE_TYPE, QUERYPARAM_SCOPE | ||
| QUERYPARAM_CODE_CHALLENGE_METHOD, QUERYPARAM_RESPONSE_TYPE, `scope=openid${scopes ? ` ${scopes.join(" ")}` : ''}` |
There was a problem hiding this comment.
The inline scope string construction is complex and hard to read. Consider extracting this logic into a separate method like _buildScopeParam(scopes?: Array<string>): string that constructs the scope parameter with 'openid' as the base and appends custom scopes if provided.
| interface PKCEConfig { | ||
| redirectURL: string, | ||
| clientID: string | ||
| clientID: string, |
There was a problem hiding this comment.
The scopes property lacks documentation explaining its purpose and that 'openid' is automatically included. Add a JSDoc comment to clarify that this array should contain additional scopes beyond 'openid', which is always present by default.
| clientID: string, | |
| clientID: string, | |
| /** | |
| * Additional scopes to request during authentication. | |
| * 'openid' is always included by default; specify only extra scopes here. | |
| */ |
When using the onelogin-node-sdk library to integrate oneLogin to our product we ended up with a situation where we needed to add scopes to get access to custom parameters that our application in oneLogin includes. but the library in its current state uses only the
openidscope with no way of adding more.This change allows the library to set custom scopes via the
Configuremethod of apkceobject. these scopes are added after theopenidscope (because that is a required scope).