1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/api/identity/identity_get_auth_token_error.h"
#include <string_view>
#include "chrome/browser/extensions/api/identity/identity_constants.h"
namespace extensions {
// static
IdentityGetAuthTokenError IdentityGetAuthTokenError::FromMintTokenAuthError(
std::string_view error_message) {
return IdentityGetAuthTokenError(State::kMintTokenAuthFailure, error_message);
}
// static
IdentityGetAuthTokenError
IdentityGetAuthTokenError::FromGetAccessTokenAuthError(
std::string_view error_message) {
return IdentityGetAuthTokenError(State::kGetAccessTokenAuthFailure,
error_message);
}
IdentityGetAuthTokenError::IdentityGetAuthTokenError()
: IdentityGetAuthTokenError(State::kNone) {}
IdentityGetAuthTokenError::IdentityGetAuthTokenError(State state)
: IdentityGetAuthTokenError(state, std::string_view()) {}
IdentityGetAuthTokenError::State IdentityGetAuthTokenError::state() const {
return state_;
}
std::string IdentityGetAuthTokenError::ToString() const {
switch (state_) {
case State::kNone:
return std::string();
case State::kInvalidClientId:
return identity_constants::kInvalidClientId;
case State::kEmptyScopes:
return identity_constants::kInvalidScopes;
case State::kMintTokenAuthFailure:
case State::kGetAccessTokenAuthFailure:
return identity_constants::kAuthFailure + error_message_;
case State::kNoGrant:
case State::kGaiaConsentInteractionRequired:
case State::kGaiaConsentInteractionAlreadyRunning:
return identity_constants::kNoGrant;
case State::kRemoteConsentFlowRejected:
return identity_constants::kUserRejected;
case State::kUserNotSignedIn:
case State::kNotAllowlistedInPublicSession:
case State::kSignInFailed:
case State::kRemoteConsentUserNotSignedIn:
return identity_constants::kUserNotSignedIn;
case State::kUserNonPrimary:
case State::kRemoteConsentUserNonPrimary:
return identity_constants::kUserNonPrimary;
case State::kBrowserSigninNotAllowed:
return identity_constants::kBrowserSigninNotAllowed;
case State::kOffTheRecord:
return identity_constants::kOffTheRecord;
case State::kRemoteConsentPageLoadFailure:
return identity_constants::kPageLoadFailure;
case State::kInvalidConsentResult:
return identity_constants::kInvalidConsentResult;
case State::kInteractivityDenied:
return identity_constants::kGetAuthTokenInteractivityDeniedError;
case State::kCannotCreateWindow:
return identity_constants::kCannotCreateWindow;
case State::kBrowserContextShutDown:
return identity_constants::kBrowserContextShutDown;
case State::kSetRemoteConsentResolutionCookiesFailed:
return identity_constants::kCannotSetRemoteConsentResolutionCookies;
}
}
IdentityGetAuthTokenError::IdentityGetAuthTokenError(State state,
std::string_view error)
: state_(state), error_message_(error) {}
} // namespace extensions
|