Authenticate evaluates providers until one succeeds.
(ctx context.Context, r *http.Request)
| 43 | |
| 44 | // Authenticate evaluates providers until one succeeds. |
| 45 | func (m *Manager) Authenticate(ctx context.Context, r *http.Request) (*Result, *AuthError) { |
| 46 | if m == nil { |
| 47 | return nil, nil |
| 48 | } |
| 49 | providers := m.Providers() |
| 50 | if len(providers) == 0 { |
| 51 | return nil, nil |
| 52 | } |
| 53 | |
| 54 | var ( |
| 55 | missing bool |
| 56 | invalid bool |
| 57 | ) |
| 58 | |
| 59 | for _, provider := range providers { |
| 60 | if provider == nil { |
| 61 | continue |
| 62 | } |
| 63 | res, authErr := provider.Authenticate(ctx, r) |
| 64 | if authErr == nil { |
| 65 | return res, nil |
| 66 | } |
| 67 | if IsAuthErrorCode(authErr, AuthErrorCodeNotHandled) { |
| 68 | continue |
| 69 | } |
| 70 | if IsAuthErrorCode(authErr, AuthErrorCodeNoCredentials) { |
| 71 | missing = true |
| 72 | continue |
| 73 | } |
| 74 | if IsAuthErrorCode(authErr, AuthErrorCodeInvalidCredential) { |
| 75 | invalid = true |
| 76 | continue |
| 77 | } |
| 78 | return nil, authErr |
| 79 | } |
| 80 | |
| 81 | if invalid { |
| 82 | return nil, NewInvalidCredentialError() |
| 83 | } |
| 84 | if missing { |
| 85 | return nil, NewNoCredentialsError() |
| 86 | } |
| 87 | return nil, NewNoCredentialsError() |
| 88 | } |
nothing calls this directly
no test coverage detected