-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from akunzai/dotnet6
Update to .NET 6.0
- Loading branch information
Showing
42 changed files
with
210 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.