Send Origin header with requests

master
D4VID 1 year ago
parent a7327449f7
commit 2a19bbbd88

@ -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<HttpResponseMessage> 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);
}
}

@ -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");

@ -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"
}
}

Loading…
Cancel
Save