oauth2: Token.Extra should be type agnostic

Change-Id: Ic8496d10de47181f6b9c16360b5101c6314d71ee
Reviewed-on: https://go-review.googlesource.com/1653
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Burcu Dogan
2014-12-16 10:43:35 -08:00
parent ed997606a9
commit 685f9f8718
2 changed files with 37 additions and 7 deletions

View File

@@ -70,18 +70,18 @@ func (t *Token) WithExtra(extra interface{}) *Token {
return t2
}
// Extra returns an extra field returned from the server during token
// retrieval.
func (t *Token) Extra(key string) string {
// Extra returns an extra field.
// Extra fields are key-value pairs returned by the server as a
// part of the token retrieval response.
func (t *Token) Extra(key string) interface{} {
if vals, ok := t.raw.(url.Values); ok {
// TODO(jbd): Cast numeric values to int64 or float64.
return vals.Get(key)
}
if raw, ok := t.raw.(map[string]interface{}); ok {
if val, ok := raw[key].(string); ok {
return val
}
return raw[key]
}
return ""
return nil
}
// expired reports whether the token is expired.