-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add login and linking profile #111
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.
Looks good, add some notes.
The important bits are around the rest API design, the PKCS/JWA stuff, and env vars.
|
||
export class TokenExpiredError extends Error { | ||
constructor() { | ||
super('Token is expired') |
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.
worth noting the expiry time in the message
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${tokens.access_token}` } } | ||
) | ||
|
||
if (!orgsResponse.ok) throw new Error(`Could not fetch orgs from Livecycle API. ${orgsResponse.status}: ${orgsResponse.statusText}`) |
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.
should really use something like got to avoid this code duplication everywhere
|
||
const orgs = await orgsResponse.json() as Org[] | ||
|
||
let chosenOrg: Org |
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.
style nit - wrap in function chooseOrg(orgs, promptUserWithChooseOrg)
to shorten and avoid let
From a user experience, it might be worth asking the user after login if they want to link the profile and use |
|
||
logger.info('Opening browser for authentication') | ||
try { await childProcessPromise(await open(responseData.verification_uri_complete)) } catch (e) { | ||
logger.info(`Could not open browser at ${responseData.verification_uri_complete}`) |
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.
This should be a warning, and also include the error
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${tokens.access_token}` } } | ||
) | ||
|
||
if (!orgsResponse.ok) throw new Error(`Could not fetch orgs from Livecycle API. ${orgsResponse.status}: ${orgsResponse.statusText}`) |
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.
Worth including the body of the response, easier to troubleshoot/support
interval: number | ||
) => { | ||
try { | ||
while (true) { |
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.
you can use p-retry
instead of while(true)
logger.info(`Already logged in as: ${jose.decodeJwt(tokensMaybe.id_token).email} 👌`) | ||
return | ||
} | ||
tokens = await deviceFlow(loginUrl, logger, clientId) |
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.
Can be removed?
No description provided.