我试图让用户可以通过Steam进行授权。
我目前正在使用端口8080上的前端和端口5000上的后端。两个服务上都有本地SSL。
我可以通过后端通过Steam登录,并检索有关登录用户的信息、声明。问题是,成功登录后发送的cookie或声明在前端实例中不可用,因为当用户使用Steam进行授权时,它完全是通过后端进行的,因此前端无法使用WebToken、cookie或会话。
我在用
AspNet。安全OpenId(6.0.0)
AspNet。安全OpenId。蒸汽(6.0.0)
我目前在后端有以下设置
创业。配置服务中的cs
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/Authentication/SteamLogin";
options.LogoutPath = "/Authentication/SteamLogout";
options.Cookie.Domain = "https://localhost:8080"; //Tried to do some shared cookie thing but doesnt work
})
.AddSteam(options =>
{
options.ApplicationKey = "SECRET_APP_KEY";
});
AuthenticationController授权
因此,要通过蒸汽连接,您需要直接访问此位置
"https://localhost:5000/Authentication/SteamAuthorize".
通常,我会通过从前端发送GET或POST呼叫来进行身份验证,以便前端与后端建立关系。这里没有,因为您可以直接访问操作。
[AllowAnonymous]
[Route("SteamAuthorize")]
[HttpGet]
public IActionResult SteamAuthorize()
{
return Challenge(new AuthenticationProperties { RedirectUri = "/", IsPersistent = true }, "Steam");
}
AuthenticationController索引
因此,在用户通过steam成功登录后,响应将发送到此位置。
在这里,获取所获取的数据不是问题,但现在我需要在前端向后端发出请求时提供声明和身份。
[HttpGet("~/")]
public async Task<ActionResult> Index()
{
var openIdSteamId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);
var steam_userName = User.Identity.Name;
if (steam_userName != null && openIdSteamId != null)
{
var steam_userId = openIdSteamId.Value.Replace("https://steamcommunity.com/openid/id/", "");
//I've tried redirecting to the frontend which then makes a new call afterwards
//The frontend will make a new call to this "/" page and now the Claims are gone
return Redirect("https://localhost:8080/steamauthorizing");
}
return Redirect("https://localhost:8080/");
}
我试着设置选项。曲奇域=”https://localhost:8080“但这不管用。
我一直在寻找如何通过这两项服务来维持委托人和索赔。
总结一下这个问题。如何通过后端使用OpenID对第三方应用进行身份验证,前端也可以使用该身份?