Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit db81cf7

Browse files
Added unmarshal attribute for expires_in for device flow auth token
Signed-off-by: pmahindrakar-oss <prafulla.mahindrakar@gmail.com>
1 parent c1c892a commit db81cf7

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

clients/go/admin/deviceflow/payload.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ type DeviceAccessTokenRequest struct {
4040

4141
type DeviceAccessTokenResponse struct {
4242
oauth2.Token
43-
Error string `json:"error"`
43+
Error string `json:"error"`
44+
ExpiresIn int64 `json:"expires_in"` // relative seconds from now
4445
}

clients/go/admin/deviceflow/token_orchestrator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func (t TokenOrchestrator) PollTokenEndpoint(ctx context.Context, tokReq DeviceA
131131
return nil, fmt.Errorf("oauth error : %v", tokResp.Error)
132132
}
133133
} else {
134+
if secs := tokResp.ExpiresIn; secs > 0 {
135+
tokResp.Token.Expiry = time.Now().Add(time.Duration(secs) * time.Second)
136+
}
134137
// Got the auth token in the response and save it in the cache
135138
err = t.TokenCache.SaveToken(&tokResp.Token)
136139
// Saving into the cache is only considered to be a warning in this case.

clients/go/admin/deviceflow/token_orchestrator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func TestFetchFromAuthFlow(t *testing.T) {
8787
Token: oauth2.Token{
8888
AccessToken: "access_token",
8989
},
90+
ExpiresIn: 300,
9091
}
9192
darBytes, err := json.Marshal(dar)
9293
assert.Nil(t, err)
@@ -121,5 +122,6 @@ func TestFetchFromAuthFlow(t *testing.T) {
121122
assert.Nil(t, err)
122123
assert.NotNil(t, authToken)
123124
assert.Equal(t, "access_token", authToken.AccessToken)
125+
assert.True(t, authToken.Expiry.After(time.Now().Add(time.Second*200)))
124126
})
125127
}

0 commit comments

Comments
 (0)