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)
| 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) |
| 38 | func 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. |
| 56 | func authToken(token string, url string) (u *user.User, err error) { |
nothing calls this directly
no test coverage detected