MCPcopy Index your code
hub / github.com/coder/coder / SplitAPIToken

Function SplitAPIToken

coderd/httpmw/apikey.go:978–995  ·  view source on GitHub ↗

SplitAPIToken verifies the format of an API key and returns the split ID and secret. APIKeys are formatted: ${ID}-${SECRET}

(token string)

Source from the content-addressed store, hash-verified

976//
977// APIKeys are formatted: ${ID}-${SECRET}
978func SplitAPIToken(token string) (id string, secret string, err error) {
979 parts := strings.Split(token, "-")
980 if len(parts) != 2 {
981 return "", "", xerrors.Errorf("incorrect amount of API key parts, expected 2 got %d", len(parts))
982 }
983
984 // Ensure key lengths are valid.
985 keyID := parts[0]
986 keySecret := parts[1]
987 if len(keyID) != 10 {
988 return "", "", xerrors.Errorf("invalid API key ID length, expected 10 got %d", len(keyID))
989 }
990 if len(keySecret) != 22 {
991 return "", "", xerrors.Errorf("invalid API key secret length, expected 22 got %d", len(keySecret))
992 }
993
994 return keyID, keySecret, nil
995}
996
997// RedirectToLogin redirects the user to the login page with the `message` and
998// `redirect` query parameters set.

Callers 5

ExpireOauthTokenMethod · 0.92
IsAuthorizedMethod · 0.92
revokeAPIKeyInTxFunction · 0.92
TestIntegrationFunction · 0.92

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestIntegrationFunction · 0.74