Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 Copyright 2014 Google Inc | 2 Copyright 2014 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 Loading... | |
24 using Google.Apis.Auth.OAuth2.Requests; | 24 using Google.Apis.Auth.OAuth2.Requests; |
25 using Google.Apis.Auth.OAuth2.Responses; | 25 using Google.Apis.Auth.OAuth2.Responses; |
26 using Google.Apis.Util.Store; | 26 using Google.Apis.Util.Store; |
27 | 27 |
28 namespace Google.Apis.Auth.OAuth2 | 28 namespace Google.Apis.Auth.OAuth2 |
29 { | 29 { |
30 /// <summary> | 30 /// <summary> |
31 /// OAuth 2.0 verification code receiver for Windows Phone 8.1 application t hat opens a Google account form so the | 31 /// OAuth 2.0 verification code receiver for Windows Phone 8.1 application t hat opens a Google account form so the |
32 /// users can enter their credentials and accept the application access to t heir token. | 32 /// users can enter their credentials and accept the application access to t heir token. |
33 ///· | 33 ///· |
34 /// This broker most important method is <see cref="ReceiveCodeAsync"/>. | 34 /// This broker's most important method is <see cref="ReceiveCodeAsync"/>. |
jmcgrew
2014/11/25 20:46:59
broker -> broker's
peleyal
2014/11/26 02:54:00
Done.
| |
35 /// The first time it is being called, it calls <code>WebAuthenticationBroke r.AuthenticateAndContinue</code> | 35 /// The first time it is being called, it calls <code>WebAuthenticationBroke r.AuthenticateAndContinue</code> |
36 /// so the users can authorize the app to access their private resources. Wh ile calling this method the app is | 36 /// so the users can authorize the app to access their private resources. Wh ile calling this method the app is |
37 /// suspended. | 37 /// suspended. |
38 ///· | 38 ///· |
39 /// When the app is being activated again, the developer MUST stores the aut h result (which may contain the access | 39 /// When the app is being activated again, the developer MUST store the auth result (which may contain the access |
jmcgrew
2014/11/25 20:46:59
stores -> store
peleyal
2014/11/26 02:54:00
Done.
| |
40 /// code or an error) in the storage with the <code>WebAuthResult.Name</code > key. | 40 /// code or an error) in the storage with the <code>SerializableWebAuthResul t.Name</code> key. |
41 /// Then when the auth framework calls again the <see cref="ReceiveCodeAsync "/> it looks in the storage to find | 41 /// Then when the auth framework calls again the <see cref="ReceiveCodeAsync "/> it looks in the storage to find |
42 /// the auth result, and if a code was received the framework will convert i t in turn to access and refresh token. | 42 /// the auth result, and if a code was received the framework will convert i t in turn to access and refresh tokens. |
peleyal
2014/11/25 20:15:55
access and refresh tokens
peleyal
2014/11/26 02:54:00
Done.
| |
43 /// </summary> | 43 /// </summary> |
44 public class AuthorizationCodeBroker : ICodeReceiver | 44 public class AuthorizationCodeBroker : ICodeReceiver |
45 { | 45 { |
46 #region ICodeReceiver Members | 46 #region ICodeReceiver Members |
47 | 47 |
48 public string RedirectUri | 48 public string RedirectUri |
49 { | 49 { |
50 get { return GoogleAuthConsts.LocalhostRedirectUri; } | 50 get { return GoogleAuthConsts.LocalhostRedirectUri; } |
51 } | 51 } |
52 | 52 |
53 public async Task<AuthorizationCodeResponseUrl> ReceiveCodeAsync(Authori zationCodeRequestUrl url, | 53 public async Task<AuthorizationCodeResponseUrl> ReceiveCodeAsync(Authori zationCodeRequestUrl url, |
54 CancellationToken taskCancellationToken) | 54 CancellationToken taskCancellationToken) |
55 { | 55 { |
56 TaskCompletionSource<AuthorizationCodeResponseUrl> tcs = | 56 TaskCompletionSource<AuthorizationCodeResponseUrl> tcs = |
57 new TaskCompletionSource<AuthorizationCodeResponseUrl>(); | 57 new TaskCompletionSource<AuthorizationCodeResponseUrl>(); |
58 await ReceiveCodeAsync(url, tcs); | 58 await ReceiveCodeAsync(url, tcs); |
59 return tcs.Task.Result; | 59 return tcs.Task.Result; |
60 } | 60 } |
61 | 61 |
62 #endregion | |
63 | |
62 private async Task InvokeFromUIThread(Action action) | 64 private async Task InvokeFromUIThread(Action action) |
63 { | 65 { |
64 await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDi spatcherPriority.Normal, | 66 await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDi spatcherPriority.Normal, |
65 () => action()); | 67 () => action()); |
66 } | 68 } |
67 | 69 |
68 /// <summary>Asynchronously receives the authorization code.</summary> | 70 /// <summary>Asynchronously receives the authorization code.</summary> |
69 /// <param name="url">The authorization code request URL.</param> | 71 /// <param name="url">The authorization code request URL.</param> |
70 /// <param name="tcs">Task completion source whose result will be set to the authorization code.</param> | 72 /// <param name="tcs">Task completion source whose result will be set to the authorization code.</param> |
71 private async Task ReceiveCodeAsync(AuthorizationCodeRequestUrl url, | 73 private async Task ReceiveCodeAsync(AuthorizationCodeRequestUrl url, |
72 TaskCompletionSource<AuthorizationCodeResponseUrl> tcs) | 74 TaskCompletionSource<AuthorizationCodeResponseUrl> tcs) |
73 { | 75 { |
74 var result = await PasswordVaultDataStore.Default.GetAsync<WebAuthRe sult>(WebAuthResult.Name); | 76 var result = await PasswordVaultDataStore.Default.GetAsync<Serializa bleWebAuthResult>( |
77 SerializableWebAuthResult.Name); | |
75 if (result == null) | 78 if (result == null) |
76 { | 79 { |
77 // We should run WebAuthenticationBroker.AuthenticateAndContinue from the UI thread ONLY. | 80 // We should run WebAuthenticationBroker.AuthenticateAndContinue from the UI thread ONLY. |
78 await InvokeFromUIThread(() => WebAuthenticationBroker.Authentic ateAndContinue(url.Build(), | 81 await InvokeFromUIThread(() => WebAuthenticationBroker.Authentic ateAndContinue(url.Build(), |
79 new Uri(GoogleAuthConsts.LocalhostRedirectUri), null, WebAut henticationOptions.None)); | 82 new Uri(GoogleAuthConsts.LocalhostRedirectUri), null, WebAut henticationOptions.None)); |
80 ················ | 83 ················ |
81 // No need to return anything, cause the application is going to be suspended now. | 84 // No need to return anything, cause the application is going to be suspended now. |
82 return; | 85 return; |
83 } | 86 } |
84 | 87 |
(...skipping 10 matching lines...) Expand all Loading... | |
95 } | 98 } |
96 | 99 |
97 tcs.SetException(new TokenResponseException( | 100 tcs.SetException(new TokenResponseException( |
98 new TokenErrorResponse | 101 new TokenErrorResponse |
99 { | 102 { |
100 Error = result.ResponseStatus.ToString(), | 103 Error = result.ResponseStatus.ToString(), |
101 ErrorDescription = "The WebAuthenticationBroker didn't retur n a code or an error. Details: " | 104 ErrorDescription = "The WebAuthenticationBroker didn't retur n a code or an error. Details: " |
102 result.ResponseErrorDetail, | 105 result.ResponseErrorDetail, |
103 })); | 106 })); |
104 } | 107 } |
105 | |
106 #endregion | |
peleyal
2014/11/25 20:15:54
The #endregion should be before InvokeFrom UIThrea
peleyal
2014/11/26 02:54:00
Done.
| |
107 } | 108 } |
108 } | 109 } |
LEFT | RIGHT |