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

claims: add SessionID to known claims #205

Merged
merged 1 commit into from
Apr 19, 2023
Merged

claims: add SessionID to known claims #205

merged 1 commit into from
Apr 19, 2023

Conversation

AlexCuse
Copy link
Contributor

@AlexCuse AlexCuse commented Apr 18, 2023

Copy link
Member

@cainlevy cainlevy left a comment

Choose a reason for hiding this comment

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

Looks like a good direction to me!

@@ -43,6 +43,7 @@ func New(cfg *app.Config, session *sessions.Claims, accountID int, audience stri
Audience: jwt.Audience{audience},
Expiry: jwt.NewNumericDate(time.Now().Add(cfg.AccessTokenTTL)),
IssuedAt: jwt.NewNumericDate(time.Now()),
ID: session.ID,
Copy link
Member

Choose a reason for hiding this comment

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

I looked through https://www.iana.org/assignments/jwt/jwt.xhtml#claims to see if any well-known claims would be a good fit. What do you think of sid?

Copy link
Contributor Author

@AlexCuse AlexCuse Apr 18, 2023

Choose a reason for hiding this comment

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

I like it kind of surprised ID in the jwt package doesn't end up there but that was mostly just my prior ignorance of this document :)

Followed same pattern as AuthTime in this commit: 219ca73

I will open PR in the go client with same - and put a comment about the embed with a link to the file here 😄

@@ -70,6 +71,7 @@ func New(store data.RefreshTokenStore, cfg *app.Config, accountID int, authorize
Subject: string(refreshToken),
Audience: jwt.Audience{cfg.AuthNURL.String()},
IssuedAt: jwt.NewNumericDate(time.Now()),
ID: uuid.NewString(),
Copy link
Member

Choose a reason for hiding this comment

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

UUID is also my preference. 👍

@AlexCuse AlexCuse marked this pull request as ready for review April 18, 2023 18:35
@AlexCuse
Copy link
Contributor Author

moving original description here to make room for something merge worthy:

We are building MFA into our system that runs alongside authn-server and looking to deal with session refreshes. I was planning to submit a PR with an optional webhook notification that includes the old and new token values but in the process I noticed that ID in the token claims is unused - I think if we assign a value on session creation and then thread it through on refresh, we could achieve the same thing on our end without the additional call (just cache MFA status per ID instead of per token).

Open to suggestion on other ways to assign a unique ID instead of bringing in the UUID package, that felt heavy handed but wanted to get discussion on the approach started quickly. If this seems viable I will look to harden in general, if I am missing something I can go back to the webhook notification path.

@AlexCuse AlexCuse changed the title session: assign ID and carry in claims on refresh session: add ID Apr 18, 2023
@AlexCuse AlexCuse changed the title session: add ID session: add SessionID to known claims Apr 18, 2023
@AlexCuse AlexCuse changed the title session: add SessionID to known claims claims: add SessionID to known claims Apr 18, 2023
Copy link
Member

@cainlevy cainlevy left a comment

Choose a reason for hiding this comment

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

Thanks!

@AlexCuse
Copy link
Contributor Author

I added a test for session creation / parsing at least. Let me know if you have any tips on setup for TestSessionRefresher - just need to setup properly to parse the generated token and validate it carries through.

Also squashed down to a single commit to prep for merge.

@@ -41,6 +42,8 @@ func TestSessionRefresher(t *testing.T) {
assert.NoError(t, err)
assert.NotEmpty(t, identityToken)

// TODO: parse token and validate SessionID still set - what setup is needed?
Copy link
Member

Choose a reason for hiding this comment

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

have a look in server/test/asserts.go at AssertIDTokenResponse. i doubt it will be useful in whole, but it should provide an example of parsing and asserting on the JWT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's nice I was trying to think of how to use the key setup for key store, didn't think to go at it through JWT library directly. Will give a go hopefully one more force push.

Need to spend a little time tomorrow to build a docker image locally but the change itself feels very straightforward don't anticipate any problems as long as we deploy the client change with our MFA stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup that worked perfectly thanks - just force pushed the last test update.

@cainlevy cainlevy merged commit daf90eb into keratin:main Apr 19, 2023
@cainlevy
Copy link
Member

Released in v1.16.0

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.

2 participants