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

*: update refresh tokens instead of deleting and creating another #757

Merged
merged 4 commits into from
Jan 11, 2017

Conversation

ericchiang
Copy link
Contributor

The server implements a strategy called "Refresh Token Rotation" to
ensure refresh tokens can only be claimed once.

ref: https://tools.ietf.org/html/rfc6819#section-5.2.2.3

Previously "refresh_token" values in token responses where just the
ID of the internal refresh object. To implement rotation, when a
client redeemed a refresh token, the object would be deleted, a new
one created, and the new ID returned as the new "refresh_token".

However, this means there was no consistent ID for refresh tokens
internally, making things like foreign keys very hard to implement.
This is problematic for revocation features like showing all the
refresh tokens a user or client has out.

This PR updates the "refresh_token" to be an encoded protobuf
message, which holds the internal ID and a nonce. When a refresh
token is used, the nonce is updated to prevent reuse, but the ID
remains the same. Additionally it adds the timestamp of each
token's last use.

cc @rithujohn191

@ericchiang ericchiang force-pushed the constant-refresh-tokens branch 2 times, most recently from 2c8753e to 3ee1d92 Compare December 23, 2016 01:40
@ericchiang
Copy link
Contributor Author

rebase for good measure.

@ericchiang
Copy link
Contributor Author

There was a conflict with #767. Rebased, updated to include the fix, and ran the Kubernetes integration tests.

@ericchiang ericchiang added this to the v2.1.0 milestone Jan 10, 2017
@ericchiang
Copy link
Contributor Author

@rithujohn191 please take a look

@ericchiang ericchiang mentioned this pull request Jan 10, 2017
Copy link
Contributor

@rithujohn191 rithujohn191 left a comment

Choose a reason for hiding this comment

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

Everything LGTM. Just had a small doubt.

@@ -273,6 +268,10 @@ func (a *app) handleCallback(w http.ResponseWriter, r *http.Request) {
oauth2Config := a.oauth2Config(nil)
switch {
case code != "":
if state := r.FormValue("state"); state != exampleAppState {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering if there is a reason why we should not perform this check for "state" in case of 'refresh'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"state" is only part of a auth code response[0]. it's not part of a refresh event.

I think it's confusing because we're handling both the auth request redirect response (GET) and a frontend post to re-render the page (POST). Maybe we should switch this so GETs and POSTs are what determine the course of action? e.g.

switch r.Method {
case "GET":
    // ... handle state and do code exchange
case "POST":
    // ... try to refresh token
}

[0] https://tools.ietf.org/html/rfc6749#section-4.1.2

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that would definitely make the flow more clear

@ericchiang
Copy link
Contributor Author

@rithujohn191 Updated the example-app.

Copy link
Contributor

@rithujohn191 rithujohn191 left a comment

Choose a reason for hiding this comment

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

Thanks.

@rithujohn191
Copy link
Contributor

Might need a rebase?

Eric Chiang added 4 commits January 11, 2017 12:07
The server implements a strategy called "Refresh Token Rotation" to
ensure refresh tokens can only be claimed once.

ref: https://tools.ietf.org/html/rfc6819#section-5.2.2.3

Previously "refresh_token" values in token responses where just the
ID of the internal refresh object. To implement rotation, when a
client redeemed a refresh token, the object would be deleted, a new
one created, and the new ID returned as the new "refresh_token".

However, this means there was no consistent ID for refresh tokens
internally, making things like foreign keys very hard to implement.
This is problematic for revocation features like showing all the
refresh tokens a user or client has out.

This PR updates the "refresh_token" to be an encoded protobuf
message, which holds the internal ID and a nonce. When a refresh
token is used, the nonce is updated to prevent reuse, but the ID
remains the same. Additionally it adds the timestamp of each
token's last use.
@ericchiang ericchiang merged commit 3c247db into dexidp:master Jan 11, 2017
@ericchiang ericchiang deleted the constant-refresh-tokens branch January 11, 2017 20:09
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.

None yet

2 participants