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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 IDataStore dataStore = null) | 75 IDataStore dataStore = null) |
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> |
| 86 /// Asynchronously reauthorizes the user. This method should be called i
f the users want to authorize after· |
| 87 /// they revoked the token. |
| 88 /// </summary> |
| 89 /// <param name="userCredential">The current user credential. Its <see c
ref="UserCredential.Token"/> will be |
| 90 /// updated. </param> |
| 91 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> |
| 92 public static async Task ReauthorizeAsync(UserCredential userCredential, |
| 93 CancellationToken taskCancellationToken) |
| 94 { |
| 95 // Create an authorization code installed app instance and authorize
the user. |
| 96 UserCredential newUserCredential = await new AuthorizationCodeInstal
ledApp(userCredential.Flow, |
| 97 new LocalServerCodeReceiver()).AuthorizeAsync |
| 98 (userCredential.UderId, taskCancellationToken).ConfigureAwait(fa
lse); |
| 99 userCredential.Token = newUserCredential.Token; |
| 100 } |
| 101 |
85 /// <summary>The core logic for asynchronously authorizing the specified
user.</summary> | 102 /// <summary>The core logic for asynchronously authorizing the specified
user.</summary> |
86 /// <param name="initializer">The authorization code initializer.</param
> | 103 /// <param name="initializer">The authorization code initializer.</param
> |
87 /// <param name="scopes"> | 104 /// <param name="scopes"> |
88 /// 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. |
89 /// </param> | 106 /// </param> |
90 /// <param name="user">The user to authorize.</param> | 107 /// <param name="user">The user to authorize.</param> |
91 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> | 108 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> |
92 /// <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> |
93 /// <returns>User credential.</returns> | 110 /// <returns>User credential.</returns> |
94 private static async Task<UserCredential> AuthorizeAsyncCore( | 111 private static async Task<UserCredential> AuthorizeAsyncCore( |
95 GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<str
ing> scopes, string user, | 112 GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<str
ing> scopes, string user, |
96 CancellationToken taskCancellationToken, IDataStore dataStore = null
) | 113 CancellationToken taskCancellationToken, IDataStore dataStore = null
) |
97 { | 114 { |
98 initializer.Scopes = scopes; | 115 initializer.Scopes = scopes; |
99 initializer.DataStore = dataStore ?? new FileDataStore(Folder); | 116 initializer.DataStore = dataStore ?? new FileDataStore(Folder); |
100 var flow = new GoogleAuthorizationCodeFlow(initializer); | 117 var flow = new GoogleAuthorizationCodeFlow(initializer); |
101 | 118 |
102 // Create authorization code installed app instance and authorize th
e user. | 119 // Create an authorization code installed app instance and authorize
the user. |
103 return await new AuthorizationCodeInstalledApp(flow, new LocalServer
CodeReceiver()).AuthorizeAsync | 120 return await new AuthorizationCodeInstalledApp(flow, new LocalServer
CodeReceiver()).AuthorizeAsync |
104 (user, taskCancellationToken).ConfigureAwait(false); | 121 (user, taskCancellationToken).ConfigureAwait(false); |
105 } | 122 } |
106 | |
107 /// <summary> | |
108 /// Reauthorize asynchronously the user. This method should be called if
the user should be reauthorize after | |
109 /// revoking the token. | |
110 /// </summary> | |
111 /// <param name="userCredential">The current user credential. Its <see c
ref="UserCredential.Token"/></param> | |
112 /// will be updated. | |
113 /// <param name="taskCancellationToken">Cancellation token to cancel an
operation.</param> | |
114 public static async Task ReauthorizeAsync(UserCredential userCredential, | |
115 CancellationToken taskCancellationToken) | |
116 { | |
117 // Create authorization code installed app instance and authorize th
e user. | |
118 UserCredential newUserCredential = await new AuthorizationCodeInstal
ledApp(userCredential.Flow, | |
119 new LocalServerCodeReceiver()).AuthorizeAsync | |
120 (userCredential.UderId, taskCancellationToken).ConfigureAwait(fa
lse); | |
121 userCredential.Token = newUserCredential.Token; | |
122 } | |
123 } | 123 } |
124 } | 124 } |
LEFT | RIGHT |