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 getIdTokenResult implementation #3014

Merged
merged 6 commits into from
May 5, 2020
Merged

Conversation

sam-gc
Copy link
Contributor

@sam-gc sam-gc commented May 4, 2020

No description provided.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 4, 2020

Binary Size Report

Affected SDKs

No changes between base commit (6b951a1) and head commit (f47ba5b).

Test Logs

@sam-gc sam-gc requested a review from bojeil-google May 4, 2020 22:59
@sam-gc sam-gc removed the request for review from bojeil-google May 5, 2020 17:07
}

export interface ParsedToken {
[key: string]: string | ParsedToken;
Copy link
Contributor

Choose a reason for hiding this comment

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

a token can include another token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it can include a sub object yes

Copy link
Contributor

Choose a reason for hiding this comment

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

recommend naming these differently then, ParsedToken should include standardized JWT fields on it like iat, the nested object should be a FirebaseClaims

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done-ish

I changed the index signature (which needs to cover all named types as well) to be string|object|undefined, the firebase specific type is then covered.

): Promise<IdTokenResult> {
const token = await user.getIdToken(forceRefresh);
const claims = parseClaims(token);
// const firebase = claims?.firebase;
Copy link
Member

Choose a reason for hiding this comment

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

Remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


function makeJWT(claims: object): string {
const b64 = base64Encode(JSON.stringify(claims));
return `algorithm.${b64}.signature`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Alex made the point later in the review that the middle part is often called payload. It's clear that this is base64 as well. Lets be consistent with whatever you choose!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,86 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Any of this need javadoc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's the license

Copy link
Contributor

Choose a reason for hiding this comment

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

Snarky but I meant the code itself. I was just pointing to the top of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooooooh I misunderstood, my b

Copy link
Contributor

@scottcrossen scottcrossen left a comment

Choose a reason for hiding this comment

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

I don't understand the github workflow and accidentally clicked "request changes". I'm going to switch my status to "approve with nits"

@scottcrossen scottcrossen assigned sam-gc and unassigned scottcrossen May 5, 2020

export interface ParsedToken {
'exp'?: string;
'auth_time'?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like auth_time is not a standard field, do we always have it present? https://en.wikipedia.org/wiki/JSON_Web_Token#Standard_fields

Copy link
Contributor Author

@sam-gc sam-gc May 5, 2020

Choose a reason for hiding this comment

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

¯\_(ツ)_/¯ I'm just copying what the js version does. It's marked as ?: optional so no it's not necessarily always there, that's why we do the assert

if (!idToken || !idToken['exp'] || !idToken['auth_time'] || !idToken['iat']) {

Copy link
Contributor

@avolkovi avolkovi left a comment

Choose a reason for hiding this comment

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

LGTM, but I still think we should not have nested PayloadToken, we should call it something else to make it clear that it's not a nested JWT

@sam-gc sam-gc merged commit 12bfc51 into auth-next May 5, 2020
@sam-gc sam-gc deleted the samgho/id-token-result branch May 5, 2020 22:55
sam-gc added a commit that referenced this pull request May 19, 2020
@firebase firebase locked and limited conversation to collaborators Jun 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants