Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit f88eea5

Browse files
committed
Add SetTokens() as well
1 parent 2f26469 commit f88eea5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

console/login.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,21 @@ func (c *Client) SetToken(token string) *Client {
4646
defer c.Unlock()
4747

4848
c.token = token
49-
c.expiresAt = time.Now().Add(24 * time.Hour)
49+
c.expiresAt = time.Now().Add(600 * time.Second)
5050
return c
5151
}
5252

53+
// SetTokens sets the tokens
54+
func (c *Client) SetTokens(accessToken, refreshToken, idToken string, expiresAt int64) {
55+
c.Lock()
56+
defer c.Unlock()
57+
c.token = accessToken
58+
c.refreshToken = refreshToken
59+
c.idToken = idToken
60+
c.expiresAt = time.Unix(expiresAt, 0)
61+
c.tokenType = oAuthToken
62+
}
63+
5364
func (c *Client) doTokenRequest(req *http.Request) error {
5465
var tokenResponse tokenResponse
5566

console/login_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/philips-software/go-hsdp-api/console"
55
"github.com/stretchr/testify/assert"
66
"testing"
7+
"time"
78
)
89

910
func TestSetToken(t *testing.T) {
@@ -18,5 +19,8 @@ func TestSetToken(t *testing.T) {
1819
return
1920
}
2021
token := "MyToken"
22+
token2 := "TokenMy"
2123
assert.Equal(t, token, client.SetToken(token).Token())
24+
client.SetTokens(token, token2, token, time.Now().Add(10*time.Minute).Unix())
25+
assert.Equal(t, token2, client.RefreshToken())
2226
}

0 commit comments

Comments
 (0)