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

oauth2: add new RawBody field to oauth2.Token #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions internal/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type Token struct {
// Raw optionally contains extra metadata from the server
// when updating a token.
Raw interface{}

// RawBody is the response body from the oauth2 access token request/response flow
RawBody []byte
}

// tokenJSON is the struct representing the HTTP response from OAuth2
Expand Down Expand Up @@ -278,6 +281,7 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {
}
json.Unmarshal(body, &token.Raw) // no error checks for optional fields
}
token.RawBody = body
if token.AccessToken == "" {
return nil, errors.New("oauth2: server response missing access_token")
}
Expand Down
5 changes: 5 additions & 0 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type Token struct {
// mechanisms for that TokenSource will not be used.
Expiry time.Time `json:"expiry,omitempty"`

// RawBody provides access to the raw body response from
// the oauth2 authorize flow
RawBody []byte `json:"-"`

// raw optionally contains extra metadata from the server
// when updating a token.
raw interface{}
Expand Down Expand Up @@ -146,6 +150,7 @@ func tokenFromInternal(t *internal.Token) *Token {
TokenType: t.TokenType,
RefreshToken: t.RefreshToken,
Expiry: t.Expiry,
RawBody: t.RawBody,
raw: t.Raw,
}
}
Expand Down