MCPcopy Create free account
hub / github.com/MG-RAST/Shock / Auth

Function Auth

shock-server/auth/oauth/oauth.go:38–53  ·  view source on GitHub ↗

Auth takes the request authorization header and returns user bearer token "oauth" returns default url (first item in auth_oauth_url conf value)

(header string)

Source from the content-addressed store, hash-verified

36// Auth takes the request authorization header and returns user
37// bearer token "oauth" returns default url (first item in auth_oauth_url conf value)
38func Auth(header string) (*user.User, error) {
39 bearer := authHeaderType(header)
40 if bearer == "" {
41 return nil, errors.New("(oauth) Invalid authentication header, missing bearer token.")
42 }
43 oauth_url, found_url := conf.AUTH_OAUTH[bearer]
44 if bearer == "basic" {
45 return nil, errors.New("(oauth) This authentication method does not support username/password authentication. Please use your OAuth token.")
46 } else if bearer == "oauth" {
47 return authToken(strings.Split(header, " ")[1], conf.OAUTH_DEFAULT)
48 } else if found_url {
49 return authToken(strings.Split(header, " ")[1], oauth_url)
50 } else {
51 return nil, errors.New("(oauth) Invalid authentication header, unknown bearer token: " + bearer)
52 }
53}
54
55// authToken validiates token by fetching user information.
56func authToken(token string, url string) (u *user.User, err error) {

Callers

nothing calls this directly

Calls 2

authTokenFunction · 0.85
authHeaderTypeFunction · 0.70

Tested by

no test coverage detected