forked from github/github-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.go
More file actions
32 lines (25 loc) · 777 Bytes
/
token.go
File metadata and controls
32 lines (25 loc) · 777 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
package context
import (
"context"
"github.com/github/github-mcp-server/pkg/githubapi"
)
// tokenCtxKey is a context key for authentication token information
type tokenCtx string
var tokenCtxKey tokenCtx = "tokenctx"
type TokenInfo struct {
Token string
TokenType githubapi.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)
}
// 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
}