Thread-safe OAuth 2.0 authorization code flow for a Windows Phone installed application that persists end-user credentials. The AuthorizeAsync method MUST be called from the dispatcher thread! This installed app class uses an internal AuthorizationCodeInstalledApp with a Google.Apis.Auth.OAuth2.AuthorizationCodeBroker for retrieving the authorization code.
Inheritance: IAuthorizationCodeInstalledApp
 /// <summary>
 /// Asynchronously reauthorizes the user. This method should be called if the users want to authorize after 
 /// they revoked the token.
 /// </summary>
 /// <param name="userCredential">The current user credential. Its <see cref="UserCredential.Token"/> will be
 /// updated. </param>
 /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
 public static async Task ReauthorizeAsync(UserCredential userCredential,
     CancellationToken taskCancellationToken)
 {
     var installedApp = new AuthorizationCodeWPInstalledApp(userCredential.Flow);
     // Create an authorization code installed app instance and authorize the user.
     UserCredential newUserCredential = await installedApp.AuthorizeAsync(
         userCredential.UserId, taskCancellationToken).ConfigureAwait(false);
     userCredential.Token = newUserCredential.Token;
 }
Exemplo n.º 2
0
        /// <summary>The core logic for asynchronously authorizing the specified user.</summary>
        /// <param name="initializer">The authorization code initializer.</param>
        /// <param name="scopes">
        /// The scopes which indicate the Google API access your application is requesting.
        /// </param>
        /// <param name="user">The user to authenticate.</param>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        /// <returns>User credential.</returns>
        private static async Task <UserCredential> AuthorizeAsyncCore(AuthorizationCodeFlow.Initializer initializer,
                                                                      IEnumerable <string> scopes, string user, CancellationToken taskCancellationToken)
        {
            initializer.Scopes    = scopes;
            initializer.DataStore = new StorageDataStore();

            var installedApp = new AuthorizationCodeWPInstalledApp(initializer);

            return(await installedApp.AuthorizeAsync(user, taskCancellationToken).ConfigureAwait(false));
        }
        /// <summary>
        /// Asynchronously reauthorizes the user. This method should be called if the users want to authorize after
        /// they revoked the token.
        /// </summary>
        /// <param name="userCredential">The current user credential. Its <see cref="UserCredential.Token"/> will be
        /// updated. </param>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        public static async Task ReauthorizeAsync(UserCredential userCredential,
                                                  CancellationToken taskCancellationToken)
        {
            var installedApp = new AuthorizationCodeWPInstalledApp(userCredential.Flow);
            // Create an authorization code installed app instance and authorize the user.
            UserCredential newUserCredential = await installedApp.AuthorizeAsync(userCredential.UserId,
                                                                                 taskCancellationToken).ConfigureAwait(false);

            userCredential.Token = newUserCredential.Token;
        }
        /// <summary>Asynchronously authorizes the specified user.</summary>
        /// <remarks>
        /// It uses <see cref="Google.Apis.Util.Store.PasswordVaultDataStore"/> as the flow's data store by default.
        /// </remarks>
        /// <param name="clientSecrets">The client secrets URI.</param>
        /// <param name="scopes">
        /// The scopes which indicate the Google API access your application is requesting.
        /// </param>
        /// <param name="user">The user to authorize.</param>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        /// <returns>User credential.</returns>
        private static async Task <UserCredential> AuthorizeAsync(ClientSecrets clientSecrets,
                                                                  IEnumerable <string> scopes, string user, CancellationToken taskCancellationToken)
        {
            var initializer = new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = clientSecrets,
                Scopes        = scopes,
                DataStore     = new PasswordVaultDataStore()
            };

            var installedApp = new AuthorizationCodeWPInstalledApp(new GoogleAuthorizationCodeFlow(initializer));

            return(await installedApp.AuthorizeAsync(user, taskCancellationToken).ConfigureAwait(false));
        }
        /// <summary>The core logic for asynchronously authorizing the specified user.</summary>
        /// <param name="initializer">The authorization code initializer.</param>
        /// <param name="scopes">
        /// The scopes which indicate the Google API access your application is requesting.
        /// </param>
        /// <param name="user">The user to authenticate.</param>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        /// <returns>User credential.</returns>
        private static async Task<UserCredential> AuthorizeAsyncCore(AuthorizationCodeFlow.Initializer initializer,
            IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken)
        {
            initializer.Scopes = scopes;
            initializer.DataStore = new StorageDataStore();

            var installedApp = new AuthorizationCodeWPInstalledApp(initializer);
            return await installedApp.AuthorizeAsync(user, taskCancellationToken).ConfigureAwait(false);
        }
        /// <summary>Asynchronously authorizes the specified user.</summary>
        /// <remarks>
        /// It uses <see cref="Google.Apis.Util.Store.PasswordVaultDataStore"/> as the flow's data store by default.
        /// </remarks>
        /// <param name="clientSecrets">The client secrets URI.</param>
        /// <param name="scopes">
        /// The scopes which indicate the Google API access your application is requesting.
        /// </param>
        /// <param name="user">The user to authorize.</param>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        /// <returns>User credential.</returns>
        private static async Task<UserCredential> AuthorizeAsync(ClientSecrets clientSecrets,
            IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken)
        {
            var initializer = new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = clientSecrets,
                Scopes = scopes,
                DataStore = new PasswordVaultDataStore()
            };

            var installedApp = new AuthorizationCodeWPInstalledApp(new GoogleAuthorizationCodeFlow(initializer));
            return await installedApp.AuthorizeAsync(user, taskCancellationToken).ConfigureAwait(false);
        }