Skip to content
Merged
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
14 changes: 12 additions & 2 deletions go/src/oauth2client/oauth2client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,19 @@ func retrieveAccessToken(url string, params url.Values) (*Token, error) {
if err != nil {
return nil, err
}

var token *Token
err := json.Unmarshal(body, &token)
return token, err

if err := json.Unmarshal(body, &token); err != nil {
return nil, err
}

if token.ExpiresIn != nil {
expiry := int64(time.Now().Unix()) + int64(*token.ExpiresIn)
token.Expiry = time.Unix(expiry, 0)
token.ExpiresIn = nil
}
return token, nil
}

// Run 3LO verification. Sends a request to auth_uri with a verification code.
Expand Down
14 changes: 13 additions & 1 deletion go/src/oauth2client/token.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package oauth2client

import (
"time"
)

// Definition for OAuth2 token type.
// Referenced from https://godoc.org/golang.org/x/oauth2#Token
type Token struct {
Expand All @@ -16,6 +20,14 @@ type Token struct {
// if it expires.
RefreshToken string `json:"refresh_token,omitempty"`

// Expiry is the optional expiration time of the access token.
//
// If zero, TokenSource implementations will reuse the same
// token forever and RefreshToken or equivalent
// mechanisms for that TokenSource will not be used.
Expiry time.Time `json:"expiry,omitempty"`
// contains filtered or unexported fields

// ExpiresIn is the optional expiration time in seconds.
ExpiresIn int `json:"expires_in,omitempty"`
ExpiresIn *int `json:"expires_in,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it part of OAuth 2 spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"expires_in" is part of the oauth 2 spec, but I didn't see "expiry", which is defined in golang's token

}