Skip to content

Commit 1269ce9

Browse files
authored
Merge pull request #95 from Azure-Samples/jennyf/bearer
fix cap on bearer
2 parents fb064f4 + efd2dd1 commit 1269ce9

File tree

10 files changed

+42
-154
lines changed

10 files changed

+42
-154
lines changed

1-Call-MSGraph/daemon-console/AuthenticationConfig.cs

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
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.
243

254
using Microsoft.Extensions.Configuration;
265
using System;

1-Call-MSGraph/daemon-console/Program.cs

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
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.
3+
244
using Microsoft.Identity.Client;
255
using Newtonsoft.Json.Linq;
266
using System;

1-Call-MSGraph/daemon-console/ProtectedApiCallHelper.cs

+8-29
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
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.
243

254
using Newtonsoft.Json;
265
using Newtonsoft.Json.Linq;
@@ -50,11 +29,11 @@ public ProtectedApiCallHelper(HttpClient httpClient)
5029

5130

5231
/// <summary>
53-
/// Calls the protected Web API and processes the result
32+
/// Calls the protected web API and processes the result
5433
/// </summary>
55-
/// <param name="webApiUrl">Url of the Web API to call (supposed to return Json)</param>
56-
/// <param name="accessToken">Access token used as a bearer security token to call the Web API</param>
57-
/// <param name="processResult">Callback used to process the result of the call to the Web API</param>
34+
/// <param name="webApiUrl">URL of the web API to call (supposed to return Json)</param>
35+
/// <param name="accessToken">Access token used as a bearer security token to call the web API</param>
36+
/// <param name="processResult">Callback used to process the result of the call to the web API</param>
5837
public async Task CallWebApiAndProcessResultASync(string webApiUrl, string accessToken, Action<JObject> processResult)
5938
{
6039
if (!string.IsNullOrEmpty(accessToken))
@@ -64,7 +43,7 @@ public async Task CallWebApiAndProcessResultASync(string webApiUrl, string acces
6443
{
6544
HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
6645
}
67-
defaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
46+
defaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
6847

6948
HttpResponseMessage response = await HttpClient.GetAsync(webApiUrl);
7049
if (response.IsSuccessStatusCode)
@@ -77,7 +56,7 @@ public async Task CallWebApiAndProcessResultASync(string webApiUrl, string acces
7756
else
7857
{
7958
Console.ForegroundColor = ConsoleColor.Red;
80-
Console.WriteLine($"Failed to call the Web Api: {response.StatusCode}");
59+
Console.WriteLine($"Failed to call the web API: {response.StatusCode}");
8160
string content = await response.Content.ReadAsStringAsync();
8261

8362
// Note that if you got reponse.Code == 403 and reponse.content.code == "Authorization_RequestDenied"

2-Call-OwnApi/TodoList-WebApi/Controllers/TodoListController.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
25
using System.Collections.Generic;
36
using System.Linq;
47
using System.Threading.Tasks;

2-Call-OwnApi/TodoList-WebApi/Models/TodoItem.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace TodoList_WebApi.Models
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace TodoList_WebApi.Models
25
{
36
public class TodoItem
47
{

2-Call-OwnApi/TodoList-WebApi/Program.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Hosting;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.AspNetCore.Hosting;
25
using Microsoft.Extensions.Hosting;
36

47
namespace TodoList_WebApi

2-Call-OwnApi/TodoList-WebApi/Startup.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Authentication.JwtBearer;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.AspNetCore.Authentication.JwtBearer;
25
using Microsoft.AspNetCore.Builder;
36
using Microsoft.AspNetCore.Hosting;
47
using Microsoft.Extensions.Configuration;

2-Call-OwnApi/daemon-console/AuthenticationConfig.cs

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
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.
243

254
using Microsoft.Extensions.Configuration;
265
using System;

2-Call-OwnApi/daemon-console/Program.cs

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
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.
3+
244
using Microsoft.Identity.Client;
255
using Newtonsoft.Json.Linq;
266
using System;

2-Call-OwnApi/daemon-console/ProtectedApiCallHelper.cs

+8-29
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
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.
243

254
using Newtonsoft.Json;
265
using Newtonsoft.Json.Linq;
@@ -51,11 +30,11 @@ public ProtectedApiCallHelper(HttpClient httpClient)
5130

5231

5332
/// <summary>
54-
/// Calls the protected Web API and processes the result
33+
/// Calls the protected web API and processes the result
5534
/// </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>
5938
public async Task CallWebApiAndProcessResultASync(string webApiUrl, string accessToken, Action<IEnumerable<JObject>> processResult)
6039
{
6140
if (!string.IsNullOrEmpty(accessToken))
@@ -65,7 +44,7 @@ public async Task CallWebApiAndProcessResultASync(string webApiUrl, string acces
6544
{
6645
HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
6746
}
68-
defaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
47+
defaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
6948

7049
HttpResponseMessage response = await HttpClient.GetAsync(webApiUrl);
7150
if (response.IsSuccessStatusCode)
@@ -78,7 +57,7 @@ public async Task CallWebApiAndProcessResultASync(string webApiUrl, string acces
7857
else
7958
{
8059
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}");
8261
string content = await response.Content.ReadAsStringAsync();
8362

8463
// Note that if you got reponse.Code == 403 and reponse.content.code == "Authorization_RequestDenied"

0 commit comments

Comments
 (0)