diff --git a/OAuthClient/OriginHandler.cs b/OAuthClient/OriginHandler.cs new file mode 100644 index 0000000..308c758 --- /dev/null +++ b/OAuthClient/OriginHandler.cs @@ -0,0 +1,20 @@ +namespace OAuthClient; + +public class OriginHandler : DelegatingHandler { + private readonly string _origin; + + public OriginHandler(string origin) { + _origin = origin; + InnerHandler = new HttpClientHandler(); + } + + protected override Task SendAsync(HttpRequestMessage request, + CancellationToken cancellationToken) { + // Add the Origin header to the request + if (!request.Headers.Contains("Origin")) { + request.Headers.Add("Origin", _origin); + } + + return base.SendAsync(request, cancellationToken); + } +} \ No newline at end of file diff --git a/OAuthClient/Program.cs b/OAuthClient/Program.cs index 5e68cc8..58c11e8 100644 --- a/OAuthClient/Program.cs +++ b/OAuthClient/Program.cs @@ -3,6 +3,7 @@ using System.Security.Claims; using System.Text.Json; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.OAuth; +using OAuthClient; var builder = WebApplication.CreateBuilder(args); builder.Logging.AddConsole(); @@ -27,6 +28,7 @@ builder.Services.AddAuthentication(options => { options.TokenEndpoint = authConfig["TokenEndpoint"]!; options.UserInformationEndpoint = authConfig["UserInformationEndpoint"]!; options.SignInScheme = "Cookie"; + options.Backchannel = new HttpClient(new OriginHandler("http://localhost:5255")); options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "userId"); diff --git a/OAuthClient/appsettings.json b/OAuthClient/appsettings.json index 4b6fd43..df03158 100644 --- a/OAuthClient/appsettings.json +++ b/OAuthClient/appsettings.json @@ -8,11 +8,11 @@ "AllowedHosts": "*", "Authentication": { "OAuth": { - "ClientId": "lmao", - "ClientSecret": "yeet", - "AuthorizationEndpoint": "http://localhost:1234/oauth/authorize", - "TokenEndpoint": "http://localhost:1234/oauth/token", - "UserInformationEndpoint": "http://localhost:1234/user", + "ClientId": "5c2bbd1ed84a4a62ac74d7fcecc1788c", + "ClientSecret": "99b50d898268854b83f7a7cf30d9281b3a7b887941aeb489daf35361120af987e9f5f9457f016e553d9837511e552e1200686fbf67b5aa7ff2726b6f35b00219", + "AuthorizationEndpoint": "http://localhost:5255/api/v1/oauth/authorize", + "TokenEndpoint": "http://localhost:5255/api/v1/oauth/token", + "UserInformationEndpoint": "http://localhost:5255/api/v1/oauth/user", "CallbackPath": "/oauth-cb" } }