Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1105)

Delta Between Two Patch Sets: Src/GoogleApis.Auth/OAuth2/AuthorizationCodeInstalledApp.cs

Issue 14341043: Issue 351: Reimplement OAuth2 (Step 4): ServiceAccount and MVC (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: Created 10 years, 5 months ago
Right Patch Set: Gus comments Created 10 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Src/GoogleApis.Auth/GoogleApis.Auth.csproj ('k') | Src/GoogleApis.Auth/OAuth2/Credential.cs » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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
11 distributed under the License is distributed on an "AS IS" BASIS, 11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and 13 See the License for the specific language governing permissions and
14 limitations under the License. 14 limitations under the License.
15 */ 15 */
16 16
17 using System.Threading; 17 using System.Threading;
18 using System.Threading.Tasks; 18 using System.Threading.Tasks;
19 19
20 using Google.Apis.Auth.OAuth2.Flows;
20 using Google.Apis.Auth.OAuth2.Responses; 21 using Google.Apis.Auth.OAuth2.Responses;
21 using Google.Apis.Auth.OAuth2.Requests; 22 using Google.Apis.Auth.OAuth2.Requests;
22 using Google.Apis.Logging; 23 using Google.Apis.Logging;
23 24
24 namespace Google.Apis.Auth.OAuth2 25 namespace Google.Apis.Auth.OAuth2
25 { 26 {
26 /// <summary> 27 /// <summary>
27 /// Thread-safe OAuth 2.0 authorization code flow for an installed applicati on that persists end-user credentials. 28 /// Thread-safe OAuth 2.0 authorization code flow for an installed applicati on that persists end-user credentials.
28 /// </summary> 29 /// </summary>
29 public class AuthorizationCodeInstalledApp : IAuthorizationCodeInstalledApp 30 public class AuthorizationCodeInstalledApp : IAuthorizationCodeInstalledApp
(...skipping 19 matching lines...) Expand all
49 { 50 {
50 get { return flow; } 51 get { return flow; }
51 } 52 }
52 53
53 /// <summary>Gets the code receiver which is responsible for receiving t he authorization code.</summary> 54 /// <summary>Gets the code receiver which is responsible for receiving t he authorization code.</summary>
54 public ICodeReceiver CodeReceiver 55 public ICodeReceiver CodeReceiver
55 { 56 {
56 get { return codeReceiver; } 57 get { return codeReceiver; }
57 } 58 }
58 59
59 public async Task<UserCredential> Authorize(string userId, CancellationT oken taskCancellationToken) 60 public async Task<UserCredential> AuthorizeAsync(string userId, Cancella tionToken taskCancellationToken)
60 { 61 {
61 // Try to load a token from the data store. 62 // Try to load a token from the data store.
62 var token = await Flow.LoadTokenAsync(userId, taskCancellationToken) .ConfigureAwait(false); 63 var token = await Flow.LoadTokenAsync(userId, taskCancellationToken) .ConfigureAwait(false);
63 64
64 // If the stored token is null or it doesn't have a refresh token an d the access token is expired we need· 65 // If the stored token is null or it doesn't have a refresh token an d the access token is expired we need·
65 // to retrieve a new authorization code. 66 // to retrieve a new authorization code.
66 if (token == null || (token.RefreshToken == null && token.IsExpired( flow.Clock))) 67 if (token == null || (token.RefreshToken == null && token.IsExpired( flow.Clock)))
67 { 68 {
68 // Create a authorization code request. 69 // Create a authorization code request.
69 var redirectUri = CodeReceiver.RedirectUri; 70 var redirectUri = CodeReceiver.RedirectUri;
(...skipping 16 matching lines...) Expand all
86 token = await Flow.ExchangeCodeForTokenAsync(userId, response.Co de, CodeReceiver.RedirectUri, 87 token = await Flow.ExchangeCodeForTokenAsync(userId, response.Co de, CodeReceiver.RedirectUri,
87 taskCancellationToken).ConfigureAwait(false); 88 taskCancellationToken).ConfigureAwait(false);
88 } 89 }
89 90
90 return new UserCredential(flow, userId, token); 91 return new UserCredential(flow, userId, token);
91 } 92 }
92 93
93 #endregion 94 #endregion
94 } 95 }
95 } 96 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b