[go: nahoru, domu]

Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(151)
Delta Between Two Patch Sets: Src/GoogleApis.Auth/OAuth2/Web/AuthorizationCodeWebApp.cs
Issue 94340043: Issue 463: Provide a signout\logout method (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: Update code for WP and WinRT Created 10 years, 1 month ago
Right Patch Set: Gus' comments Created 10 years, 1 month 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/OAuth2/UserCredential.cs ('k') | no next file » | 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
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 /// </returns> 97 /// </returns>
98 public async Task<AuthResult> AuthorizeAsync(string userId, Cancellation Token taskCancellationToken) 98 public async Task<AuthResult> AuthorizeAsync(string userId, Cancellation Token taskCancellationToken)
99 { 99 {
100 // Try to load a token from the data store. 100 // Try to load a token from the data store.
101 var token = await Flow.LoadTokenAsync(userId, taskCancellationToken) .ConfigureAwait(false); 101 var token = await Flow.LoadTokenAsync(userId, taskCancellationToken) .ConfigureAwait(false);
102 102
103 // If the stored token is null or it doesn't have a refresh token an d the access token is expired, we need· 103 // If the stored token is null or it doesn't have a refresh token an d the access token is expired, we need·
104 // to retrieve a new access token. 104 // to retrieve a new access token.
105 if (token == null || (token.RefreshToken == null && token.IsExpired( flow.Clock))) 105 if (token == null || (token.RefreshToken == null && token.IsExpired( flow.Clock)))
106 { 106 {
107 // Create a authorization code request. 107 // Create an authorization code request.
108 AuthorizationCodeRequestUrl codeRequest = Flow.CreateAuthorizati onCodeRequest(redirectUri); 108 AuthorizationCodeRequestUrl codeRequest = Flow.CreateAuthorizati onCodeRequest(redirectUri);
109 109
110 // Add a random number to the end of the state so we can indicat e the original request was made by this 110 // Add a random number to the end of the state so we can indicat e the original request was made by this
111 // call. 111 // call.
112 var oauthState = state; 112 var oauthState = state;
113 if (Flow.DataStore != null) 113 if (Flow.DataStore != null)
114 { 114 {
115 var rndString = new string('9', StateRandomLength); 115 var rndString = new string('9', StateRandomLength);
116 var random = new Random().Next(int.Parse(rndString)).ToStrin g("D" + StateRandomLength); 116 var random = new Random().Next(int.Parse(rndString)).ToStrin g("D" + StateRandomLength);
117 oauthState += random; 117 oauthState += random;
118 await Flow.DataStore.StoreAsync(StateKey + userId, oauthStat e).ConfigureAwait(false); 118 await Flow.DataStore.StoreAsync(StateKey + userId, oauthStat e).ConfigureAwait(false);
119 } 119 }
120 codeRequest.State = oauthState; 120 codeRequest.State = oauthState;
121 121
122 return new AuthResult { RedirectUri = codeRequest.Build().ToStri ng() }; 122 return new AuthResult { RedirectUri = codeRequest.Build().ToStri ng() };
123 } 123 }
124 124
125 return new AuthResult { Credential = new UserCredential(flow, userId , token) }; 125 return new AuthResult { Credential = new UserCredential(flow, userId , token) };
126 } 126 }
127 } 127 }
128 } 128 }
LEFTRIGHT

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