Skip to content

Commit

Permalink
Merge pull request #64 from akunzai/dotnet6
Browse files Browse the repository at this point in the history
Update to .NET 6.0
  • Loading branch information
akunzai committed Nov 14, 2021
2 parents 9168f41 + 8dfb0fb commit e28028b
Show file tree
Hide file tree
Showing 42 changed files with 210 additions and 303 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "4.8.13",
"version": "5.0.0",
"commands": [
"reportgenerator"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Build packages
run: |
dotnet --info
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
- name: Set up .NET 5 SDK
- name: Set up .NET 6 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Build
run: |
dotnet --info
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 2.3.1 (2021-11-14)

- Floating latest dependencies for .NET 6
- [RNGCryptoServiceProvider is obsolete since .NET 6](https://github.com/dotnet/runtime/issues/40169)
- Bump System.ComponentModel.Annotations from 4.5.0 to 4.7.0

## 2.3.0 (2021-06-11)

- Floating latest dependencies for .NET Core 3.1 and .NET 5
Expand Down
3 changes: 3 additions & 0 deletions OAuth.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GSS.Authorization.OAuth2.HttpClient.Tests", "test\GSS.Authorization.OAuth2.HttpClient.Tests\GSS.Authorization.OAuth2.HttpClient.Tests.csproj", "{28080D26-3251-4619-AD9D-54381759ED2A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F0FA418E-E9E8-4A7F-835D-A00476B78754}"
ProjectSection(SolutionItems) = preProject
samples\Directory.Build.props = samples\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OAuth2HttpClientSample", "samples\OAuth2HttpClientSample\OAuth2HttpClientSample.csproj", "{D67C5C98-4344-4E1F-B809-5A91551C90EC}"
EndProject
Expand Down
11 changes: 11 additions & 0 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

</Project>
3 changes: 1 addition & 2 deletions samples/OAuth2HttpClientSample/OAuth2HttpClientSample.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
83 changes: 34 additions & 49 deletions samples/OAuth2HttpClientSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,45 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using GSS.Authorization.OAuth2;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace OAuth2HttpClientSample
static void ConfigureAuthorizerOptions(IServiceProvider resolver, AuthorizerOptions options)
{
public class Program
{
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
var clientBuilder =
hostContext.Configuration.GetValue("OAuth2:GrantFlow", "ClientCredentials")
.Equals("ClientCredentials", StringComparison.OrdinalIgnoreCase)
? services.AddOAuth2HttpClient<OAuth2HttpClient, ClientCredentialsAuthorizer>(
ConfigureAuthorizerOptions)
: services.AddOAuth2HttpClient<OAuth2HttpClient, ResourceOwnerCredentialsAuthorizer>(
ConfigureAuthorizerOptions);
clientBuilder.ConfigureHttpClient(client =>
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
});
}).Build();
var configuration = host.Services.GetRequiredService<IConfiguration>();
var configuration = resolver.GetRequiredService<IConfiguration>();
options.AccessTokenEndpoint = configuration.GetValue<Uri>("OAuth2:AccessTokenEndpoint");
options.ClientId = configuration["OAuth2:ClientId"];
options.ClientSecret = configuration["OAuth2:ClientSecret"];
options.Credentials = new NetworkCredential(
configuration["OAuth2:Credentials:UserName"],
configuration["OAuth2:Credentials:Password"]);
options.Scopes = configuration.GetSection("OAuth2:Scopes").Get<IEnumerable<string>>();
options.OnError = (code, message) => Console.Error.Write($"ERROR: [${code}]: {message}");
}

Console.WriteLine("Creating a client...");
var oauth2Client = host.Services.GetRequiredService<OAuth2HttpClient>();
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
var clientBuilder =
hostContext.Configuration.GetValue("OAuth2:GrantFlow", "ClientCredentials")
.Equals("ClientCredentials", StringComparison.OrdinalIgnoreCase)
? services.AddOAuth2HttpClient<OAuth2HttpClient, ClientCredentialsAuthorizer>(
ConfigureAuthorizerOptions)
: services.AddOAuth2HttpClient<OAuth2HttpClient, ResourceOwnerCredentialsAuthorizer>(
ConfigureAuthorizerOptions);
clientBuilder.ConfigureHttpClient(client => client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")));
}).Build();
var configuration = host.Services.GetRequiredService<IConfiguration>();

Console.WriteLine("Creating a client...");
var oauth2Client = host.Services.GetRequiredService<OAuth2HttpClient>();

Console.WriteLine("Sending a request...");
var response = await oauth2Client.HttpClient.GetAsync(configuration.GetValue<Uri>("OAuth2:ResourceEndpoint")).ConfigureAwait(false);

Console.WriteLine("Response data:");
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Console.WriteLine(data);

Console.WriteLine("Sending a request...");
var response = await oauth2Client.HttpClient.GetAsync(configuration.GetValue<Uri>("OAuth2:ResourceEndpoint")).ConfigureAwait(false);
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Console.WriteLine("Response data:");
Console.WriteLine(data);
}

private static void ConfigureAuthorizerOptions(IServiceProvider resolver, AuthorizerOptions options)
{
var configuration = resolver.GetRequiredService<IConfiguration>();
options.AccessTokenEndpoint = configuration.GetValue<Uri>("OAuth2:AccessTokenEndpoint");
options.ClientId = configuration["OAuth2:ClientId"];
options.ClientSecret = configuration["OAuth2:ClientSecret"];
options.Credentials = new NetworkCredential(
configuration["OAuth2:Credentials:UserName"],
configuration["OAuth2:Credentials:Password"]);
options.Scopes = configuration.GetSection("OAuth2:Scopes").Get<IEnumerable<string>>();
options.OnError = (code, message) =>
{
Console.Error.Write($"ERROR: [${code}]: {message}");
};
}
}
}
7 changes: 2 additions & 5 deletions samples/OAuth2HttpClientSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Information"
}
},
"OAuth2": {
"AccessTokenEndpoint": "https://example.com/oauth2/accessToken",
"AccessTokenEndpoint": "https://example.com/oauth2/token",
"ResourceEndpoint": "https://example.com/oauth2/profile",
"ClientId": "CHANGE_ME",
"ClientSecret": "CHANGE_ME",
Expand Down
3 changes: 1 addition & 2 deletions samples/OAuthHttpClientSample/OAuthHttpClientSample.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
72 changes: 29 additions & 43 deletions samples/OAuthHttpClientSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,40 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using GSS.Authorization.OAuth;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace OAuthHttpClientSample
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
public static class Program
services.AddOAuthHttpClient<OAuthHttpClient>((_, options) =>
{
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddOAuthHttpClient<OAuthHttpClient>((_, options) =>
{
options.ClientCredentials = new OAuthCredential(
hostContext.Configuration["OAuth:ClientId"],
hostContext.Configuration["OAuth:ClientSecret"]);
options.TokenCredentials = new OAuthCredential(
hostContext.Configuration["OAuth:TokenId"],
hostContext.Configuration["OAuth:TokenSecret"]);
options.SignedAsQuery = hostContext.Configuration.GetValue("OAuth:SignedAsQuery", false);
options.SignedAsBody = hostContext.Configuration.GetValue("OAuth:SignedAsBody", false);
}).ConfigureHttpClient(client =>
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
});
}).Build();
var configuration = host.Services.GetRequiredService<IConfiguration>();
options.ClientCredentials = new OAuthCredential(
hostContext.Configuration["OAuth:ClientId"],
hostContext.Configuration["OAuth:ClientSecret"]);
options.TokenCredentials = new OAuthCredential(
hostContext.Configuration["OAuth:TokenId"],
hostContext.Configuration["OAuth:TokenSecret"]);
options.SignedAsQuery = hostContext.Configuration.GetValue("OAuth:SignedAsQuery", false);
options.SignedAsBody = hostContext.Configuration.GetValue("OAuth:SignedAsBody", false);
}).ConfigureHttpClient(client => client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")));
}).Build();

Console.WriteLine("Creating a client...");
var oauthClient = host.Services.GetRequiredService<OAuthHttpClient>();
var configuration = host.Services.GetRequiredService<IConfiguration>();

Console.WriteLine("Sending a request...");
var method = new HttpMethod(configuration.GetValue("Request:Method", HttpMethod.Get.Method));
var request = new HttpRequestMessage(method, configuration.GetValue<Uri>("Request:Uri"));
var body = configuration.GetSection("Request:Body").Get<IDictionary<string, string>>();
if (body != null)
{
request.Content = new FormUrlEncodedContent(body);
}
var response = await oauthClient.HttpClient.SendAsync(request).ConfigureAwait(false);
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Console.WriteLine("Response data:");
Console.WriteLine(data);
}
}
Console.WriteLine("Creating a client...");
var oauthClient = host.Services.GetRequiredService<OAuthHttpClient>();

Console.WriteLine("Sending a request...");
var method = new HttpMethod(configuration.GetValue("Request:Method", HttpMethod.Get.Method));
var request = new HttpRequestMessage(method, configuration.GetValue<Uri>("Request:Uri"));
var body = configuration.GetSection("Request:Body").Get<IDictionary<string, string>>();
if (body != null)
{
request.Content = new FormUrlEncodedContent(body);
}
var response = await oauthClient.HttpClient.SendAsync(request).ConfigureAwait(false);

Console.WriteLine("Response data:");
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Console.WriteLine(data);
9 changes: 3 additions & 6 deletions samples/OAuthHttpClientSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Information"
}
},
"OAuth": {
Expand All @@ -14,7 +11,7 @@
"TokenSecret": "CHANGE_ME"
},
"Request": {
"Uri": "https://example.com/oauth/profile",
"Method": "GET"
"Method": "GET",
"Uri": "https://example.com/oauth/profile"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,9 +24,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="McMaster.Extensions.Hosting.CommandLine" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit e28028b

Please sign in to comment.