-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: PKCE #35
feat: PKCE #35
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM! Just a few suggestions on organising the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New changes needed due to OpenID Discovery endpoint changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me in general, left a few comments
Will leave it to @mantariksh to have the final say on PR approval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Will leave it to @mantariksh to have the final say on PR approval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
starting with comments on the README first!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gtml gooks tood mo le
release plan should minimally test against sgID production rather than a local sgID server, and ideally test in a production environment rather than a local environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gtml gooks tood mo le
release plan should minimally test against sgID production rather than a local sgID server, and ideally test in a production environment rather than a local environment
yup totally agree - here is a draft of the release plan which involves how the release will be done and testing in local + prod + a mix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did one last sanity check , lgtm!
Problem
Supporting the [Proof Key for Code Exchange (PKCE)](https://www.rfc-editor.org/rfc/rfc7636) extension to OAuth 2.0 is a current best practice for preventing authorisation code interception attacks in native apps. As per [RFC 8252 (OAuth 2.0 for Native Apps)](https://www.rfc-editor.org/rfc/rfc8252):
Since it prevents auth code injection attacks, it is useful for client types other than native apps as well.
This PR is linked to this issue
Solution
High-level principles
As this is a relatively large PR which involves breaking changes, I would like to highlight a few high-level principles that were kept in mind during development and which should be achieved through the code changes.
This is in line with what we have been doing so far where we would like to keep the SDK dummy. This is so that if we would like to make any changes (e.g. with validation), we are able to modify our servers directly instead of updating our SDK (as not all RPs will update their SDKs).
This is achieved by not validating the ABNF of the codeChallenge and codeVerifier received in
authorizationUrl
andcallback
respectively. (Especially because validation bugs are easier to commit and harder to rectify)As we are maintaining a public SDK for people to use, we need to be very aware of what exactly we are exposing for developers to import. If we export function
a
, we have to continue maintaininga
as an export in future versions as developers might be relying on them.This is achieved by refactoring the
SgidClient
class into it's own file and keepingindex.ts
solely as a tunnel for exports. Additionally, we are now exporting the SDK types so developers with TypeScript can make use of them.With this PR, the API of the SDK is changing (i.e. the function signature is different). Specifically, the functions now take in an instead of sequential parameters.
This is because as the list of parameters gets longer this (i) makes it harder to remember which input corresponds to which parameter and (ii) makes it very confusing when there are optional parameters - users would have to enter
undefined
for the optional parameters they do not want to fill in just to reach the parameter they have to fill in.Features:
PKCE related changes
generatePkcePair
,generateCodeVerifier
andgenerateCodeChallenge
functions based onopenid-client
generator
functions in thegenerators.ts
fileauthorizationUrl
function params to take in an objectcodeChallenge
andparametercodeChallengeMethod
callback
function params to take in an objectcodeVerifier
parametergeneratePkcePair
,generateCodeVerifier
andgenerateCodeChallenge
functionsauthorizationUrl
andcallback
SDK improvement related changes
userinfo
function params to take in an objectopenid myinfo.nric_number
toopenid myinfo.name
SgidClient
class into its own filesgidClient.ts
and extracted types intotypes.ts
sgidClient.ts
,types.ts
,generators.ts
andutil.ts
throughindex.ts
(to be explicit about what we want exported)apiVersion
as a parameter for the constructor and use a hardcodedAPI_VERSION
constantv2
appended (in the constructor)Turn offRemoveeslint-no-throw-sync-func
ESLint ruleREADME related changes
Non-implemented changes
- Changing the constructor param fromredirectUri
toredirectUris
Tests
generatePkcePair
,generateCodeVerifier
, andgenerateCodeChallenge
authorizationUrl
andcallback
functionsVerified that all tests are passing
