LEFT | RIGHT |
1 /* | 1 /* |
2 Copyright 2013 Google Inc | 2 Copyright 2013 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 { | 76 { |
77 var initializer = new GoogleAuthorizationCodeFlow.Initializer | 77 var initializer = new GoogleAuthorizationCodeFlow.Initializer |
78 { | 78 { |
79 ClientSecretsStream = clientSecretsStream, | 79 ClientSecretsStream = clientSecretsStream, |
80 }; | 80 }; |
81 return await AuthorizeAsyncCore(initializer, scopes, user, taskCance
llationToken, dataStore) | 81 return await AuthorizeAsyncCore(initializer, scopes, user, taskCance
llationToken, dataStore) |
82 .ConfigureAwait(false); | 82 .ConfigureAwait(false); |
83 } | 83 } |
84 | 84 |
85 /// <summary> | 85 /// <summary> |
86 /// Reauthorizes asynchronously the user. This method should be called i
f the user should be reauthorize after | 86 /// Asynchronously reauthorizes the user. This method should be called i
f the users want to authorize after |
87 /// revoking the token. | 87 /// they revoked the token. |
88 /// </summary> | 88 /// </summary> |
89 /// <param name="userCredential">The current user credential. Its <see c
ref="UserCredential.Token"/></param> | 89 /// <param name="userCredential">The current user credential. Its <see c
ref="UserCredential.Token"/> will be |
90 /// will be updated. | 90 /// updated. </param> |
91 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> | 91 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> |
92 public static async Task ReauthorizeAsync(UserCredential userCredential, | 92 public static async Task ReauthorizeAsync(UserCredential userCredential, |
93 CancellationToken taskCancellationToken) | 93 CancellationToken taskCancellationToken) |
94 { | 94 { |
95 // Create authorization code installed app instance and authorize th
e user. | 95 // Create an authorization code installed app instance and authorize
the user. |
96 UserCredential newUserCredential = await new AuthorizationCodeInstal
ledApp(userCredential.Flow, | 96 UserCredential newUserCredential = await new AuthorizationCodeInstal
ledApp(userCredential.Flow, |
97 new LocalServerCodeReceiver()).AuthorizeAsync | 97 new LocalServerCodeReceiver()).AuthorizeAsync |
98 (userCredential.UderId, taskCancellationToken).ConfigureAwait(fa
lse); | 98 (userCredential.UderId, taskCancellationToken).ConfigureAwait(fa
lse); |
99 userCredential.Token = newUserCredential.Token; | 99 userCredential.Token = newUserCredential.Token; |
100 } | 100 } |
101 | 101 |
102 /// <summary>The core logic for asynchronously authorizing the specified
user.</summary> | 102 /// <summary>The core logic for asynchronously authorizing the specified
user.</summary> |
103 /// <param name="initializer">The authorization code initializer.</param
> | 103 /// <param name="initializer">The authorization code initializer.</param
> |
104 /// <param name="scopes"> | 104 /// <param name="scopes"> |
105 /// The scopes which indicate the Google API access your application is
requesting. | 105 /// The scopes which indicate the Google API access your application is
requesting. |
106 /// </param> | 106 /// </param> |
107 /// <param name="user">The user to authorize.</param> | 107 /// <param name="user">The user to authorize.</param> |
108 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> | 108 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> |
109 /// <param name="dataStore">The data store, if not specified a file data
store will be used.</param> | 109 /// <param name="dataStore">The data store, if not specified a file data
store will be used.</param> |
110 /// <returns>User credential.</returns> | 110 /// <returns>User credential.</returns> |
111 private static async Task<UserCredential> AuthorizeAsyncCore( | 111 private static async Task<UserCredential> AuthorizeAsyncCore( |
112 GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<str
ing> scopes, string user, | 112 GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<str
ing> scopes, string user, |
113 CancellationToken taskCancellationToken, IDataStore dataStore = null
) | 113 CancellationToken taskCancellationToken, IDataStore dataStore = null
) |
114 { | 114 { |
115 initializer.Scopes = scopes; | 115 initializer.Scopes = scopes; |
116 initializer.DataStore = dataStore ?? new FileDataStore(Folder); | 116 initializer.DataStore = dataStore ?? new FileDataStore(Folder); |
117 var flow = new GoogleAuthorizationCodeFlow(initializer); | 117 var flow = new GoogleAuthorizationCodeFlow(initializer); |
118 | 118 |
119 // Create authorization code installed app instance and authorize th
e user. | 119 // Create an authorization code installed app instance and authorize
the user. |
120 return await new AuthorizationCodeInstalledApp(flow, new LocalServer
CodeReceiver()).AuthorizeAsync | 120 return await new AuthorizationCodeInstalledApp(flow, new LocalServer
CodeReceiver()).AuthorizeAsync |
121 (user, taskCancellationToken).ConfigureAwait(false); | 121 (user, taskCancellationToken).ConfigureAwait(false); |
122 } | 122 } |
123 } | 123 } |
124 } | 124 } |
LEFT | RIGHT |