1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
6 #define IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
16 #endif // defined(__OBJC__)
22 #include "base/callback.h"
26 enum AuthenticationErrorCategory {
28 kAuthenticationErrorCategoryUnknownErrors,
29 // Authorization errors.
30 kAuthenticationErrorCategoryAuthorizationErrors,
31 // Authorization errors with HTTP_FORBIDDEN (403) error code.
32 kAuthenticationErrorCategoryAuthorizationForbiddenErrors,
33 // Network server errors includes parsing error and should be treated as
34 // transient/offline errors.
35 kAuthenticationErrorCategoryNetworkServerErrors,
36 // User cancellation errors should be handled by treating them as a no-op.
37 kAuthenticationErrorCategoryUserCancellationErrors,
38 // User identity not found errors.
39 kAuthenticationErrorCategoryUnknownIdentityErrors,
42 // Interface that provides support for ProfileOAuth2TokenServiceIOS.
43 class ProfileOAuth2TokenServiceIOSProvider {
45 typedef base::Callback<void(NSString* token,
47 NSError* error)> AccessTokenCallback;
49 ProfileOAuth2TokenServiceIOSProvider() {};
50 virtual ~ProfileOAuth2TokenServiceIOSProvider() {};
52 // Initializes the shared authentication library. This method should be called
53 // when loading credentials if the user is signed in to Chrome via the shared
54 // authentication library.
55 virtual void InitializeSharedAuthentication() = 0;
57 // Returns the ids of all accounts.
58 virtual std::vector<std::string> GetAllAccountIds() = 0;
60 // Starts fetching an access token for the account with id |account_id| with
61 // the given |scopes|. Once the token is obtained, |callback| is called.
62 virtual void GetAccessToken(const std::string& account_id,
63 const std::string& client_id,
64 const std::string& client_secret,
65 const std::set<std::string>& scopes,
66 const AccessTokenCallback& callback) = 0;
68 // Returns the authentication error category of |error|.
69 virtual AuthenticationErrorCategory GetAuthenticationErrorCategory(
70 NSError* error) const = 0;
75 #endif // IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_