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

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

Issue 13972043: Issue 351: Reimplement OAuth2 (Step 3 - Tests, Flows and Credential) (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: minor Created 10 years, 6 months ago
Right Patch Set: minor 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 13 matching lines...) Expand all
24 namespace Google.Apis.Auth.OAuth2 24 namespace Google.Apis.Auth.OAuth2
25 { 25 {
26 /// <summary>A helper utility to manage the authorization code flow.</summar y> 26 /// <summary>A helper utility to manage the authorization code flow.</summar y>
27 public class GoogleWebAuthenticationBroker 27 public class GoogleWebAuthenticationBroker
28 { 28 {
29 /// <summary>The folder which is used by the <seealso cref="Google.Apis. Util.Store.FileDataStore"/>.</summary> 29 /// <summary>The folder which is used by the <seealso cref="Google.Apis. Util.Store.FileDataStore"/>.</summary>
30 public static string Folder = "Google.Apis.Auth"; 30 public static string Folder = "Google.Apis.Auth";
31 31
32 /// <summary>Asynchronously authenticates the specified user.</summary> 32 /// <summary>Asynchronously authenticates the specified user.</summary>
33 /// <remarks> 33 /// <remarks>
34 /// In case no data store is specified, <seealso cref="Google.Apis.Util. Store.FileDataStore"/> is used by· 34 /// In case no data store is specified, <seealso cref="Google.Apis.Util. Store.FileDataStore"/> will be used by·
35 /// default. 35 /// default.
36 /// </remarks> 36 /// </remarks>
37 /// <param name="clientSecrets">The client secrets</param> 37 /// <param name="clientSecrets">The client secrets.</param>
38 /// <param name="scopes">The scopes</param> 38 /// <param name="scopes">
39 /// <param name="user">The user to authenticate</param> 39 /// The scopes which indicate the Google API access your application is requesting.
40 /// <param name="taskCancellationToken">Cancellation token to cancel an operation</param> 40 /// </param>
41 /// <param name="dataStore">The data store. If not specified a file data store will be used</param> 41 /// <param name="user">The user to authenticate.</param>
42 /// <returns>User credential</returns> 42 /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
43 public static async Task<Credential> AuthenticateAsync(ClientSecrets cli entSecrets, IEnumerable<string> scopes, 43 /// <param name="dataStore">The data store, if not specified a file data store will be used.</param>
44 string user, CancellationToken taskCancellationToken, IDataStore dat aStore = null) 44 /// <returns>User credential.</returns>
45 public static async Task<UserCredential> AuthenticateAsync(ClientSecrets clientSecrets,
46 IEnumerable<string> scopes, string user, CancellationToken taskCance llationToken,
47 IDataStore dataStore = null)
45 { 48 {
46 var initializer = new GoogleAuthorizationCodeFlow.Initializer 49 var initializer = new GoogleAuthorizationCodeFlow.Initializer
47 { 50 {
48 ClientSecrets = clientSecrets, 51 ClientSecrets = clientSecrets,
49 }; 52 };
50 return await AuthenticateAsyncCore(initializer, scopes, user, taskCa ncellationToken, dataStore); 53 return await AuthenticateAsyncCore(initializer, scopes, user, taskCa ncellationToken, dataStore);
51 } 54 }
52 55
53 /// <summary>Asynchronously authenticates the specified user.</summary> 56 /// <summary>Asynchronously authenticates the specified user.</summary>
54 /// <remarks> 57 /// <remarks>
55 /// In case no data store is specified, <seealso cref="Google.Apis.Util. Store.FileDataStore"/> is used by· 58 /// In case no data store is specified, <seealso cref="Google.Apis.Util. Store.FileDataStore"/> will be used by·
56 /// default. 59 /// default.
57 /// </remarks> 60 /// </remarks>
58 /// <param name="clientSecretsStream"> 61 /// <param name="clientSecretsStream">
59 /// The client secrets stream. The authorization code flow constructor i s responsible for disposing the stream 62 /// The client secrets stream. The authorization code flow constructor i s responsible for disposing the stream.
60 /// </remarks> 63 /// </remarks>
61 /// <param name="scopes">The scopes</param> 64 /// <param name="scopes">
62 /// <param name="user">The user to authenticate</param> 65 /// The scopes which indicate the Google API access your application is requesting.
63 /// <param name="taskCancellationToken">Cancellation token to cancel an operation</param> 66 /// </param>
64 /// <param name="dataStore">The data store. If not specified a file data store will be used</param> 67 /// <param name="user">The user to authenticate.</param>
65 /// <returns>User credential</returns> 68 /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
66 public static async Task<Credential> AuthenticateAsync(Stream clientSecr etsStream, IEnumerable<string> scopes, 69 /// <param name="dataStore">The data store, if not specified a file data store will be used.</param>
67 string user, CancellationToken taskCancellationToken, IDataStore dat aStore = null) 70 /// <returns>User credential.</returns>
71 public static async Task<UserCredential> AuthenticateAsync(Stream client SecretsStream,
72 IEnumerable<string> scopes, string user, CancellationToken taskCance llationToken,
73 IDataStore dataStore = null)
68 { 74 {
69 var initializer = new GoogleAuthorizationCodeFlow.Initializer 75 var initializer = new GoogleAuthorizationCodeFlow.Initializer
70 { 76 {
71 ClientSecretsStream = clientSecretsStream, 77 ClientSecretsStream = clientSecretsStream,
72 }; 78 };
73 return await AuthenticateAsyncCore(initializer, scopes, user, taskCa ncellationToken, dataStore); 79 return await AuthenticateAsyncCore(initializer, scopes, user, taskCa ncellationToken, dataStore);
74 } 80 }
75 81
76 /// <summary>The core logic for asynchronously authenticating the specif ied user.</summary> 82 /// <summary>The core logic for asynchronously authenticating the specif ied user.</summary>
77 /// <param name="initializer">The authorization code initializer</param> 83 /// <param name="initializer">The authorization code initializer.</param >
78 /// <param name="scopes">The scopes</param> 84 /// <param name="scopes">
79 /// <param name="user">The user to authenticate</param> 85 /// The scopes which indicate the Google API access your application is requesting.
80 /// <param name="taskCancellationToken">Cancellation token to cancel an operation</param> 86 /// </param>
81 /// <param name="dataStore">The data store, if not specified a file data store will be used</param> 87 /// <param name="user">The user to authenticate.</param>
82 /// <returns>User credential</returns> 88 /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
83 private static async Task<Credential> AuthenticateAsyncCore(Authorizatio nCodeFlow.Initializer initializer, 89 /// <param name="dataStore">The data store, if not specified a file data store will be used.</param>
90 /// <returns>User credential.</returns>
91 private static async Task<UserCredential> AuthenticateAsyncCore(Authoriz ationCodeFlow.Initializer initializer,
84 IEnumerable<string> scopes, string user, CancellationToken taskCance llationToken, 92 IEnumerable<string> scopes, string user, CancellationToken taskCance llationToken,
85 IDataStore dataStore = null) 93 IDataStore dataStore = null)
86 { 94 {
87 initializer.Scopes = scopes; 95 initializer.Scopes = scopes;
88 initializer.DataStore = dataStore ?? new FileDataStore(Folder); 96 initializer.DataStore = dataStore ?? new FileDataStore(Folder);
89 var flow = new GoogleAuthorizationCodeFlow(initializer); 97 var flow = new GoogleAuthorizationCodeFlow(initializer);
90 98
91 // Create authorization code installed app instance and authorize th e user. 99 // Create authorization code installed app instance and authorize th e user.
92 return await new AuthorizationCodeInstalledApp(flow, new LocalServer CodeReceiver()).Authorize 100 return await new AuthorizationCodeInstalledApp(flow, new LocalServer CodeReceiver()).Authorize
93 (user, taskCancellationToken); 101 (user, taskCancellationToken);
94 } 102 }
95 } 103 }
96 } 104 }
LEFTRIGHT

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