AspNet.Security.OAuth.Discord登录时出现OAuthtokenendpointfailure:BadRequest。
创始人
2024-09-20 06:30:15
0

这个问题通常是由于未正确配置OAuth设置或由于传递的参数不正确而引起的。为解决此问题,应该仔细检查OAuth设置和传递的参数是否准确,并参考以下示例中的代码进行调整:

services.AddAuthentication() .AddDiscord(options => { options.ClientId = Configuration["Discord:ClientId"]; options.ClientSecret = Configuration["Discord:ClientSecret"]; options.Scope.Add("identify"); options.Scope.Add("email"); options.TokenEndpoint = "https://discord.com/api/oauth2/token"; options.UserInformationEndpoint = "https://discord.com/api/users/@me"; options.SaveTokens = true; options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); options.ClaimActions.MapJsonKey(ClaimTypes.Name, "username"); options.ClaimActions.MapJsonKey(ClaimTypes.Email, "email"); options.Events = new OAuthEvents { OnCreatingTicket = async context => { string url = "https://discord.com/api/users/@me/guilds"; var response = await context.Backchannel.GetAsync(url, context.HttpContext.RequestAborted); response.EnsureSuccessStatusCode(); var guilds = JsonSerializer.Deserialize>(await response.Content.ReadAsStringAsync());

                var adminIds = Configuration["Discord:AdminIds"].Split(',').ToList();
                context.Principal.AddIdentity(new ClaimsIdentity(adminIds.Select(id => new Claim(ClaimTypes.Role, id))));
            }
        };
    });

在这里,我们配置了Discord的ClientId和ClientSecret,并设置了必要的范围、终结点和事件。我们还添加了一个OAuth事件,OnCreatingTicket,以在创建凭证时向用户声明角色。

使用上述代码示例,您可以重新配置您的OAuth设置并正确传递参数,以避免登录时出现OAuth token endpoint failure: BadRequest错误。

相关内容

热门资讯

透视辅助!epoker透视(透... 透视辅助!epoker透视(透视)约局吧开挂,教程举措(新版有挂)-哔哩哔哩该软件可以轻松地帮助玩家...
透视解迷!wepoker能不能... 您好,wepoker有透视底牌吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
透视必备!wepoker有透视... 透视必备!wepoker有透视底牌吗(透视)wepoker破解器激活码,教程讲义(详细教程)-哔哩哔...
透视关于!pokemmo内置修... 透视关于!pokemmo内置修改器(透视)pokemmo修改器手机版,教程方针(有挂详细)-哔哩哔哩...
透视详细!hhpoker透视码... 透视详细!hhpoker透视码(透视)wepoker辅助器是真的吗,教程步骤(的确有挂)-哔哩哔哩1...
透视科普!wepoker轻量版... 透视科普!wepoker轻量版透视方法(透视)红龙poker透视指令,教程窍要(有挂解惑)-哔哩哔哩...
透视详细!wepoker好友局... 透视详细!wepoker好友局透视(透视)德普之星怎么开辅助,教程资料(确实有挂)-哔哩哔哩1、透视...
透视普及!佛手在线大菠萝智能辅... 透视普及!佛手在线大菠萝智能辅助器(透视)哈糖大菠萝有挂吗,教程窍要(有人有挂)-哔哩哔哩亲,关键说...
透视教你!wpk系统是否存在透... 透视教你!wpk系统是否存在透视行为(透视)wepoker分析,教程机巧(有挂头条)-哔哩哔哩1、这...
透视教你!aapoker插件(... 透视教你!aapoker插件(透视)we-poker辅助,教程手筋(有挂详情)-哔哩哔哩1、we-p...