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

Side by Side Diff: Src/GoogleApis.Auth/OAuth2/Flows/GoogleAuthorizationCodeFlow.cs

Issue 94340043: Issue 463: Provide a signout\logout method (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Gus' comments Created 9 years, 10 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:
View unified diff | Download patch
OLDNEW
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; 17 using System;
18 using System.Net.Http;
19 using System.Threading;
20 using System.Threading.Tasks;
18 21
19 using Google.Apis.Auth.OAuth2.Requests; 22 using Google.Apis.Auth.OAuth2.Requests;
23 using Google.Apis.Auth.OAuth2.Responses;
24 using Google.Apis.Json;
20 25
21 namespace Google.Apis.Auth.OAuth2.Flows 26 namespace Google.Apis.Auth.OAuth2.Flows
22 { 27 {
23 /// <summary> 28 /// <summary>
24 /// Google specific authorization code flow which inherits from <seealso cre f="AuthorizationCodeFlow"/>. 29 /// Google specific authorization code flow which inherits from <seealso cre f="AuthorizationCodeFlow"/>.
25 /// </summary> 30 /// </summary>
26 public class GoogleAuthorizationCodeFlow : AuthorizationCodeFlow 31 public class GoogleAuthorizationCodeFlow : AuthorizationCodeFlow
27 { 32 {
33 private readonly string revokeTokenUrl;
34
35 /// <summary>Gets the token revocation URL.</summary>
36 public string RevokeTokenUrl { get { return revokeTokenUrl; } }
37
28 /// <summary>Constructs a new Google authorization code flow.</summary> 38 /// <summary>Constructs a new Google authorization code flow.</summary>
29 public GoogleAuthorizationCodeFlow(AuthorizationCodeFlow.Initializer ini tializer) 39 public GoogleAuthorizationCodeFlow(Initializer initializer)
30 : base(initializer) 40 : base(initializer)
31 { 41 {
42 revokeTokenUrl = initializer.RevokeTokenUrl;
32 } 43 }
33 44
34 public override AuthorizationCodeRequestUrl CreateAuthorizationCodeReque st(string redirectUri) 45 public override AuthorizationCodeRequestUrl CreateAuthorizationCodeReque st(string redirectUri)
35 { 46 {
36 return new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationSe rverUrl)) 47 return new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationSe rverUrl))
37 { 48 {
38 ClientId = ClientSecrets.ClientId, 49 ClientId = ClientSecrets.ClientId,
39 Scope = string.Join(" ", Scopes), 50 Scope = string.Join(" ", Scopes),
40 RedirectUri = redirectUri 51 RedirectUri = redirectUri
41 }; 52 };
42 } 53 }
43 54
55 public override async Task RevokeTokenAsync(string userId, string token,
56 CancellationToken taskCancellationToken)
57 {
58 GoogleRevokeTokenRequest request = new GoogleRevokeTokenRequest(new Uri(RevokeTokenUrl))
59 {
60 Token = token
61 };
62 var httpRequest = new HttpRequestMessage(HttpMethod.Get, request.Bui ld());
63
64 var response = await HttpClient.SendAsync(httpRequest, taskCancellat ionToken).ConfigureAwait(false);
65 if (!response.IsSuccessStatusCode)
66 {
67 var content = await response.Content.ReadAsStringAsync().Configu reAwait(false);
68 var error = NewtonsoftJsonSerializer.Instance.Deserialize<TokenE rrorResponse>(content);
69 throw new TokenResponseException(error);
70 }
71
72 await DeleteTokenAsync(userId, taskCancellationToken);
73 }
74
44 /// <summary>An initializer class for Google authorization code flow. </ summary> 75 /// <summary>An initializer class for Google authorization code flow. </ summary>
45 public new class Initializer : AuthorizationCodeFlow.Initializer 76 public new class Initializer : AuthorizationCodeFlow.Initializer
46 { 77 {
78 /// <summary>Gets or sets the token revocation URL.</summary>
79 public string RevokeTokenUrl { get; set; }
80
47 /// <summary> 81 /// <summary>
48 /// Constructs a new initializer. Sets Authorization server URL to· 82 /// Constructs a new initializer. Sets Authorization server URL to·
49 /// <seealso cref="GoogleAuthConsts.AuthorizationUrl"/>, and Token s erver URL to· 83 /// <seealso cref="GoogleAuthConsts.AuthorizationUrl"/>, and Token s erver URL to·
50 /// <seealso cref="GoogleAuthConsts.TokenUrl"/>. 84 /// <seealso cref="GoogleAuthConsts.TokenUrl"/>.
51 /// </summary> 85 /// </summary>
52 public Initializer() 86 public Initializer()
53 : base(GoogleAuthConsts.AuthorizationUrl, GoogleAuthConsts.Token Url) 87 : base(GoogleAuthConsts.AuthorizationUrl, GoogleAuthConsts.Token Url)
54 { 88 {
89 RevokeTokenUrl = GoogleAuthConsts.RevokeTokenUrl;
55 } 90 }
56 } 91 }
57 } 92 }
58 } 93 }
OLDNEW
« no previous file with comments | « Src/GoogleApis.Auth/OAuth2/Flows/AuthorizationCodeFlow.cs ('k') | Src/GoogleApis.Auth/OAuth2/Flows/IAuthorizationCodeFlow.cs » ('j') | no next file with comments »

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