Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Use ID token on refresh if access token is not a JWT #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,23 @@ func getRefreshedToken(conf *oauth2.Config, t string) (jose.JWT, string, time.Ti
return jose.JWT{}, "", time.Time{}, time.Duration(0), err
}
refreshExpiresIn := time.Until(tkn.Expiry)
token, identity, err := parseToken(tkn.AccessToken)

rawIDToken, ok := tkn.Extra("id_token").(string)
if !ok {
return jose.JWT{}, "", time.Time{}, time.Duration(0), errors.New("unable to obtain id token")
Copy link
Author

Choose a reason for hiding this comment

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

I guess we don't need to fail here if we still can parse the access token

}

token, identity, err := parseToken(rawIDToken)
if err != nil {
return jose.JWT{}, "", time.Time{}, time.Duration(0), err
}

access, id, err := parseToken(tkn.AccessToken)
if err == nil {
token = access
identity = id
}

return token, tkn.RefreshToken, identity.ExpiresAt, refreshExpiresIn, nil
}

Expand Down