forked from remote/oauth2
google: minor tweaks
Change-Id: Ic0e6363b19bbfd40df6b7b15322abf43c9990688
This commit is contained in:
@@ -88,7 +88,11 @@ type tokenSource struct {
|
|||||||
func (ts tokenSource) Token() (*oauth2.Token, error) {
|
func (ts tokenSource) Token() (*oauth2.Token, error) {
|
||||||
conf := ts.conf
|
conf := ts.conf
|
||||||
|
|
||||||
subjectToken, err := conf.parse().retrieveSubjectToken(conf)
|
typedCredSource := conf.parse()
|
||||||
|
if typedCredSource == nil {
|
||||||
|
return nil, fmt.Errorf("google: unable to parse credential source")
|
||||||
|
}
|
||||||
|
subjectToken, err := typedCredSource.retrieveSubjectToken(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -118,10 +122,9 @@ func (ts tokenSource) Token() (*oauth2.Token, error) {
|
|||||||
}
|
}
|
||||||
if stsResp.ExpiresIn < 0 {
|
if stsResp.ExpiresIn < 0 {
|
||||||
return nil, fmt.Errorf("google/oauth2: got invalid expiry from security token service")
|
return nil, fmt.Errorf("google/oauth2: got invalid expiry from security token service")
|
||||||
} else if stsResp.ExpiresIn > 0 {
|
} else if stsResp.ExpiresIn >= 0 {
|
||||||
accessToken.Expiry = now().Add(time.Duration(stsResp.ExpiresIn) * time.Second)
|
accessToken.Expiry = now().Add(time.Duration(stsResp.ExpiresIn) * time.Second)
|
||||||
}
|
}
|
||||||
// TODO: For reviewers- what should I do if ExpiresIn is equal to 0? Would that correspond to a one-use token, or something else?
|
|
||||||
|
|
||||||
if stsResp.RefreshToken != "" {
|
if stsResp.RefreshToken != "" {
|
||||||
accessToken.RefreshToken = stsResp.RefreshToken
|
accessToken.RefreshToken = stsResp.RefreshToken
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func TestToken_Func(t *testing.T) {
|
|||||||
|
|
||||||
tok, err := ourTS.Token()
|
tok, err := ourTS.Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %e", err)
|
t.Fatalf("Unexpected error: %e", err)
|
||||||
}
|
}
|
||||||
if got, want := tok.AccessToken, correctAT; got != want {
|
if got, want := tok.AccessToken, correctAT; got != want {
|
||||||
t.Errorf("Unexpected access token: got %v, but wanted %v", got, want)
|
t.Errorf("Unexpected access token: got %v, but wanted %v", got, want)
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ type fsTest struct {
|
|||||||
var testFsUntyped = fsTest{
|
var testFsUntyped = fsTest{
|
||||||
name: "UntypedFileSource",
|
name: "UntypedFileSource",
|
||||||
cs: CredentialSource{
|
cs: CredentialSource{
|
||||||
File: "../../testdata/externalaccount/3pi_cred.txt",
|
File: "./testdata/3pi_cred.txt",
|
||||||
},
|
},
|
||||||
want: "street123",
|
want: "street123",
|
||||||
}
|
}
|
||||||
var testFsTypeText = fsTest{
|
var testFsTypeText = fsTest{
|
||||||
name: "TextFileSource",
|
name: "TextFileSource",
|
||||||
cs: CredentialSource{
|
cs: CredentialSource{
|
||||||
File: "../../testdata/externalaccount/3pi_cred.txt",
|
File: "./testdata/3pi_cred.txt",
|
||||||
Format: format{Type: fileTypeText},
|
Format: format{Type: fileTypeText},
|
||||||
},
|
},
|
||||||
want: "street123",
|
want: "street123",
|
||||||
@@ -38,7 +38,7 @@ var testFsTypeText = fsTest{
|
|||||||
var testFsTypeJSON = fsTest{
|
var testFsTypeJSON = fsTest{
|
||||||
name: "JSONFileSource",
|
name: "JSONFileSource",
|
||||||
cs: CredentialSource{
|
cs: CredentialSource{
|
||||||
File: "../../testdata/externalaccount/3pi_cred.json",
|
File: "./testdata/3pi_cred.json",
|
||||||
Format: format{Type: fileTypeJSON, SubjectTokenFieldName: "SubjToken"},
|
Format: format{Type: fileTypeJSON, SubjectTokenFieldName: "SubjToken"},
|
||||||
},
|
},
|
||||||
want: "321road",
|
want: "321road",
|
||||||
|
|||||||
Reference in New Issue
Block a user