Skip to content
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

Merged
merged 21 commits into from
Aug 14, 2023
Merged

Add login and linking profile #111

merged 21 commits into from
Aug 14, 2023

Conversation

AssafKr
Copy link
Contributor

@AssafKr AssafKr commented Jun 21, 2023

No description provided.

Copy link
Contributor

@Yshayy Yshayy left a 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.

packages/cli/src/commands/login.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/profile/link.ts Show resolved Hide resolved
packages/core/src/profile/link.ts Outdated Show resolved Hide resolved
packages/core/src/profile/link.ts Show resolved Hide resolved
packages/cli/src/commands/profile/link.ts Show resolved Hide resolved
packages/core/src/profile/link.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved

export class TokenExpiredError extends Error {
constructor() {
super('Token is expired')
Copy link
Collaborator

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

packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/login.ts Outdated Show resolved Hide resolved
packages/core/src/profile/link.ts Outdated Show resolved Hide resolved
packages/core/src/profile/link.ts Outdated Show resolved Hide resolved
{ 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}`)
Copy link
Collaborator

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
Copy link
Collaborator

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

packages/core/src/profile/link.ts Show resolved Hide resolved
@Yshayy
Copy link
Contributor

Yshayy commented Jun 21, 2023

From a user experience, it might be worth asking the user after login if they want to link the profile and use this.config.runCommand('profile:link') if so.


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}`)
Copy link
Collaborator

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}`)
Copy link
Collaborator

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) {
Copy link
Collaborator

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

@AssafKr AssafKr merged commit f4c5de3 into main Aug 14, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants