forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 83
/
token.go
34 lines (28 loc) · 826 Bytes
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2018 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package scm
import (
"context"
"time"
)
type (
// Token represents the credentials used to authorize
// the requests to access protected resources.
Token struct {
Token string
Refresh string
Expires time.Time
}
// TokenSource returns a token.
TokenSource interface {
Token(context.Context) (*Token, error)
}
// TokenKey is the key to use with the context.WithValue
// function to associate an Token value with a context.
TokenKey struct{}
)
// WithContext returns a copy of parent in which the token value is set
func WithContext(parent context.Context, token *Token) context.Context {
return context.WithValue(parent, TokenKey{}, token)
}