/* Copyright 2013 Google Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ using System; using System.Threading; using System.Threading.Tasks; using Google.Apis.Auth.OAuth2.Responses; using Google.Apis.Auth.OAuth2.Requests; using Google.Apis.Util; using Google.Apis.Util.Store; namespace Google.Apis.Auth.OAuth2.Flows { /// OAuth 2.0 authorization code flow that manages and persists end-user credentials. public interface IAuthorizationCodeFlow : IDisposable { /// Gets the method for presenting the access token to the resource server. IAccessMethod AccessMethod { get; } /// Gets the clock. IClock Clock { get; } /// Gets the data store used to store the credentials. IDataStore DataStore { get; } /// /// Asynchronously loads the user's token using the flow's /// . /// /// User identifier /// Cancellation token to cancel operation /// Token response Task LoadTokenAsync(string userId, CancellationToken taskCancellationToken); /// /// Asynchronously deletes the user's token using the flow's /// . /// /// User identifier. /// Cancellation token to cancel operation. Task DeleteTokenAsync(string userId, CancellationToken taskCancellationToken); /// Creates an authorization code request with the specified redirect URI. AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri); /// Asynchronously exchanges code with a token. /// User identifier. /// Authorization code received from the authorization server. /// Redirect URI which is used in the token request. /// Cancellation token to cancel operation. /// Token response which contains the access token. Task ExchangeCodeForTokenAsync(string userId, string code, string redirectUri, CancellationToken taskCancellationToken); /// Asynchronously refreshes an access token using a refresh token. /// User identifier. /// Refresh token which is used to get a new access token. /// Cancellation token to cancel operation. /// Token response which contains the access token and the input refresh token. Task RefreshTokenAsync(string userId, string refreshToken, CancellationToken taskCancellationToken); /// /// Asynchronously revokes the specified token. This method disconnects the user's account from the OAuth 2.0 /// application. It should be called upon removing the user account from the site. /// /// If revoking the token succeeds, the user's credential is removed from the data store and the user MUST /// authorize the application again before the application can access the user's private resources. /// /// User identifier. /// Access token to be revoked. /// Cancellation token to cancel operation. /// true if the token was revoked successfully. Task RevokeTokenAsync(string userId, string token, CancellationToken taskCancellationToken); /// /// Indicates if a new token needs to be retrieved and stored regardless of normal circumstances. /// bool ShouldForceTokenRetrieval(); } }