SplitToken splits the token from " . . ".
(token string)
| 91 | |
| 92 | // SplitToken splits the token from "<prefix>.<id>.<key>". |
| 93 | func SplitToken(token string) (tokenType TokenType, id, key string, err error) { |
| 94 | parts := strings.Split(token, ".") |
| 95 | if len(parts) != 3 { |
| 96 | return "", "", "", errInvalidToken.New() |
| 97 | } |
| 98 | switch TokenType(parts[0]) { |
| 99 | case APIKey, AccessToken, RefreshToken, AuthorizationCode, SessionToken: |
| 100 | return TokenType(parts[0]), parts[1], parts[2], nil |
| 101 | default: |
| 102 | return "", "", "", errInvalidToken.New() |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // JoinToken joins the token as "<prefix>.<id>.<key>". |
| 107 | func JoinToken(tokenType TokenType, id, key string) string { |