-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathtoken.go
More file actions
39 lines (31 loc) · 941 Bytes
/
token.go
File metadata and controls
39 lines (31 loc) · 941 Bytes
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
35
36
37
38
39
package context
import (
"context"
"github.com/github/github-mcp-server/pkg/utils"
)
// tokenCtxKey is a context key for authentication token information
type tokenCtx string
var tokenCtxKey tokenCtx = "tokenctx"
type TokenInfo struct {
Token string
TokenType utils.TokenType
ScopesFetched bool
Scopes []string
}
// WithTokenInfo adds TokenInfo to the context
func WithTokenInfo(ctx context.Context, tokenInfo *TokenInfo) context.Context {
return context.WithValue(ctx, tokenCtxKey, tokenInfo)
}
func SetTokenScopes(ctx context.Context, scopes []string) {
if tokenInfo, ok := GetTokenInfo(ctx); ok {
tokenInfo.Scopes = scopes
tokenInfo.ScopesFetched = true
}
}
// GetTokenInfo retrieves the authentication token from the context
func GetTokenInfo(ctx context.Context) (*TokenInfo, bool) {
if tokenInfo, ok := ctx.Value(tokenCtxKey).(*TokenInfo); ok {
return tokenInfo, true
}
return nil, false
}