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. 4 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_ 7 8 #if defined(__OBJC__) 9 @class NSDate; 10 @class NSError; 11 @class NSString; 12 #else 13 class NSDate; 14 class NSError; 15 class NSString; 16 #endif // defined(__OBJC__) 17 18 #include <set> 19 #include <string> 20 #include <vector> 21 22 #include "base/callback.h" 23 24 namespace ios { 25 26 enum AuthenticationErrorCategory { 27 // Unknown errors. 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, 40 }; 41 42 // Interface that provides support for ProfileOAuth2TokenServiceIOS. 43 class ProfileOAuth2TokenServiceIOSProvider { 44 public: 45 typedef base::Callback<void(NSString* token, 46 NSDate* expiration, 47 NSError* error)> AccessTokenCallback; 48 ProfileOAuth2TokenServiceIOSProvider()49 ProfileOAuth2TokenServiceIOSProvider() {}; ~ProfileOAuth2TokenServiceIOSProvider()50 virtual ~ProfileOAuth2TokenServiceIOSProvider() {}; 51 52 // Returns whether authentication is using the shared authentication library. 53 virtual bool IsUsingSharedAuthentication() const = 0; 54 55 // Initializes the shared authentication library. This method should be called 56 // when loading credentials if the user is signed in to Chrome via the shared 57 // authentication library. 58 virtual void InitializeSharedAuthentication() = 0; 59 60 // Returns the ids of all accounts. 61 virtual std::vector<std::string> GetAllAccountIds() = 0; 62 63 // Starts fetching an access token for the account with id |account_id| with 64 // the given |scopes|. Once the token is obtained, |callback| is called. 65 virtual void GetAccessToken(const std::string& account_id, 66 const std::string& client_id, 67 const std::string& client_secret, 68 const std::set<std::string>& scopes, 69 const AccessTokenCallback& callback) = 0; 70 71 // Returns the authentication error category of |error|. 72 virtual AuthenticationErrorCategory GetAuthenticationErrorCategory( 73 NSError* error) const = 0; 74 }; 75 76 } // namespace ios 77 78 #endif // IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_ 79