-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth.go
39 lines (32 loc) · 855 Bytes
/
auth.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
35
36
37
38
39
package fly
import (
"context"
"strings"
)
type CLISessionAuth struct {
CLISession
}
// StartCLISessionWebAuth starts a session with the platform via web auth
func StartCLISessionWebAuth(machineName string, signup bool) (CLISession, error) {
return StartCLISession(machineName, map[string]interface{}{
"signup": signup,
"target": "auth",
})
}
// GetAccessTokenForCLISession Obtains the access token for the session
func GetAccessTokenForCLISession(ctx context.Context, id string) (string, error) {
val, err := GetCLISessionState(ctx, id)
if err != nil {
return "", err
}
return val.AccessToken, nil
}
func AuthorizationHeader(token string) string {
for _, tok := range strings.Split(token, ",") {
switch pfx, _, _ := strings.Cut(tok, "_"); pfx {
case "fm1r", "fm2":
return "FlyV1 " + token
}
}
return "Bearer " + token
}