1
- /*
2
- The MIT License (MIT)
3
-
4
- Copyright (c) 2015 Microsoft Corporation
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
23
- */
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
24
3
25
4
using Newtonsoft . Json ;
26
5
using Newtonsoft . Json . Linq ;
@@ -51,11 +30,11 @@ public ProtectedApiCallHelper(HttpClient httpClient)
51
30
52
31
53
32
/// <summary>
54
- /// Calls the protected Web API and processes the result
33
+ /// Calls the protected web API and processes the result
55
34
/// </summary>
56
- /// <param name="webApiUrl">Url of the Web API to call (supposed to return Json)</param>
57
- /// <param name="accessToken">Access token used as a bearer security token to call the Web API</param>
58
- /// <param name="processResult">Callback used to process the result of the call to the Web API</param>
35
+ /// <param name="webApiUrl">URL of the web API to call (supposed to return Json)</param>
36
+ /// <param name="accessToken">Access token used as a bearer security token to call the web API</param>
37
+ /// <param name="processResult">Callback used to process the result of the call to the web API</param>
59
38
public async Task CallWebApiAndProcessResultASync ( string webApiUrl , string accessToken , Action < IEnumerable < JObject > > processResult )
60
39
{
61
40
if ( ! string . IsNullOrEmpty ( accessToken ) )
@@ -65,7 +44,7 @@ public async Task CallWebApiAndProcessResultASync(string webApiUrl, string acces
65
44
{
66
45
HttpClient . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
67
46
}
68
- defaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "bearer " , accessToken ) ;
47
+ defaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer " , accessToken ) ;
69
48
70
49
HttpResponseMessage response = await HttpClient . GetAsync ( webApiUrl ) ;
71
50
if ( response . IsSuccessStatusCode )
@@ -78,7 +57,7 @@ public async Task CallWebApiAndProcessResultASync(string webApiUrl, string acces
78
57
else
79
58
{
80
59
Console . ForegroundColor = ConsoleColor . Red ;
81
- Console . WriteLine ( $ "Failed to call the Web Api : { response . StatusCode } ") ;
60
+ Console . WriteLine ( $ "Failed to call the web API : { response . StatusCode } ") ;
82
61
string content = await response . Content . ReadAsStringAsync ( ) ;
83
62
84
63
// Note that if you got reponse.Code == 403 and reponse.content.code == "Authorization_RequestDenied"
0 commit comments