簡體   English   中英

[Web API]AspNet.Security.OAuth.BattleNet OAuth 2.0 問題

[英][Web API]AspNet.Security.OAuth.BattleNet OAuth 2.0 issue

基本上我的使用戰網按鈕登錄在這里發送請求:

     services.AddAuthentication(options =>
        {
            options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        })
            .AddCookie(options =>
            {
                options.LoginPath = "/login";
                options.LogoutPath = "/logout";
            })
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidateAudience = true,
                    ValidateLifetime = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer = Configuration["Jwt:Issuer"],
                    ValidAudience = Configuration["Jwt:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            })
            .AddBattleNet(options =>
            {
                options.ClientId = Configuration["BattleNet:ClientId"];
                options.ClientSecret = Configuration["BattleNet:ClientSecret"];
                options.Region = BattleNetAuthenticationRegion.Europe;

            })

     [AllowAnonymous]
    [HttpPost(nameof(ExternalLogin))]
    public IActionResult ExternalLogin(string provider, string returnUrl = null)
    {
        var properties = new AuthenticationProperties
        {
            RedirectUri = Url.Action("ExternalLoginCallback"),
            Items =
            {
                { "scheme", provider},
                { "returnUrl", returnUrl }
            }
        };
        return Challenge(properties, provider);
    }

突然間我收到了這個錯誤

CORS 錯誤

跨域請求被阻止:同源策略不允許讀取https://eu.battle.net/oauth/authorize?client_id= *&scope=d3.profile%20openid&response_type=code&redirect_uri=https%3A%2F%2Flocalhost 的遠程資源%3A44333%2Fapi%2Fuser%2Fexternallogincallback&state=CfDJ8GNva7rF4-dPly4Z3xuUAIb6108sCNggQc6reYXjMJrGmdWZbri-N715ueCZ2Ksw9Q47k8SX1xG-c3zDck-mXT8h8mvEY5_41ox7C9OsU-PStXqUsD6npNcMBhCr16Qh1valIQ6REKTMjLiilO5wbnx1349I2SwQfJevGwKZqC4o4PElfF6kPaPmRa5Eslquh4Sfwbn3HTKeaArxx2v8jD4. (原因:缺少 CORS header 'Access-Control-Allow-Origin')。

CORS 錯誤

HTTP 請求

HTTP 請求

如果我在另一個選項卡中打開此請求,我將獲得身份驗證並重定向到ExternalLoginCallback

PS:我正在使用AspNet.Security.OAuth.BattleNet而我沒有使用ASP.NET 核心身份進行身份驗證(使用自定義邏輯)。

您不應該使用 AJAX/XHR 啟動授權代碼流。 相反,只需將您的用戶重定向到您的ExternalLogin端點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM