@@ -27,6 +27,8 @@ The OAuth2Manager is different than the existing WinRT [WebAuthenticationBroker]
27
27
28
28
The following example demonstrates how to perform an authorization code request using the OAuth2Manager API in Windows App SDK:
29
29
30
+ # [ C++] ( #tab/cpp )
31
+
30
32
``` cpp
31
33
// Get the WindowId for the application window
32
34
Microsoft::UI::WindowId parentWindowId = this ->AppWindow ().Id();
52
54
}
53
55
```
54
56
57
+ # [C#](#tab/csharp)
58
+
55
59
```csharp
56
60
// Get the WindowId for the application window
57
61
Microsoft.UI.WindowId parentWindowId = this.AppWindow.Id;
78
82
}
79
83
```
80
84
85
+ ---
86
+
81
87
### Exchange authorization code for access token
82
88
83
89
The following example demonstrates how to exchange an authorization code for an access token using the OAuth2Manager API in Windows App SDK:
84
90
91
+ # [ C++] ( #tab/cpp )
92
+
85
93
``` cpp
86
94
AuthResponse authResponse = authRequestResult.Response();
87
95
TokenRequestParams tokenRequestParams = TokenRequestParams::CreateForAuthorizationCodeRequest(authResponse);
124
132
}
125
133
```
126
134
135
+ # [C#](#tab/csharp)
136
+
127
137
```csharp
128
138
AuthResponse authResponse = authRequestResult.Response;
129
139
TokenRequestParams tokenRequestParams = TokenRequestParams.CreateForAuthorizationCodeRequest(authResponse);
@@ -167,10 +177,14 @@ else
167
177
}
168
178
```
169
179
180
+ ---
181
+
170
182
### Refresh an access token
171
183
172
184
The following example shows how to refresh an access token using the OAuth2Manager API in Windows App SDK:
173
185
186
+ # [ C++] ( #tab/cpp )
187
+
174
188
``` cpp
175
189
TokenRequestParams tokenRequestParams = TokenRequestParams::CreateForRefreshToken(refreshToken);
176
190
ClientAuthentication clientAuth = ClientAuthentication::CreateForBasicAuthorization(L" my_client_id" ,
207
221
}
208
222
```
209
223
224
+ # [C#](#tab/csharp)
225
+
210
226
```csharp
211
227
TokenRequestParams tokenRequestParams = TokenRequestParams.CreateForRefreshToken(refreshToken);
212
228
ClientAuthentication clientAuth = ClientAuthentication.CreateForBasicAuthorization("my_client_id",
@@ -243,10 +259,14 @@ else
243
259
}
244
260
```
245
261
262
+ ---
263
+
246
264
### Complete an authorization request
247
265
248
266
Finally, to complete an authorization request from a protocol activation, use the following code:
249
267
268
+ # [ C++] ( #tab/cpp )
269
+
250
270
``` cpp
251
271
void App::OnActivated (const IActivatedEventArgs& args)
252
272
{
@@ -263,6 +283,8 @@ void App::OnActivated(const IActivatedEventArgs& args)
263
283
}
264
284
```
265
285
286
+ # [C#](#tab/csharp)
287
+
266
288
```csharp
267
289
protected override void OnActivated(IActivatedEventArgs args)
268
290
{
@@ -279,6 +301,8 @@ protected override void OnActivated(IActivatedEventArgs args)
279
301
}
280
302
```
281
303
304
+ ---
305
+
282
306
## Related content
283
307
284
308
[ WebAuthenticationBroker] ( /uwp/api/windows.security.authentication.web.webauthenticationbroker )
0 commit comments