aspnet-contrib / AspNet.Security.OAuth.Providers

OAuth 2.0 social authentication providers for ASP.NET Core
Apache License 2.0
2.38k stars 538 forks source link

add wechat official account providers. #790

Open mrhoun opened 1 year ago

mrhoun commented 1 year ago

https://developers.weixin.qq.com/doc/offiaccount/en/OA_Web_Apps/Wechat_webpage_authorization.html

LeaFrock commented 1 year ago

It seems that the current AspNet.Security.OAuth.Weixin should support your requirement, as long as you use the specific official account options instead of default ones.

After a quick check of mine, as least you should write the following codes for example,


AuthenticationBuilder builder = services.AddAuthentication();

builder.AddWeixin(opt => 
{
    // NOT use the default, "https://open.weixin.qq.com/connect/qrconnect"
    opt.AuthorizationEndpoint = "https://open.weixin.qq.com/connect/oauth2/authorize";
    // opt.Scope.Clear();
    opt.Scope.Add("snsapi_base");
    opt.Scope.Add("snsapi_userinfo");
});

You may have to take a try first. The source codes are not very complex, so you can even copy and debug them in your project if you meet other problems. Your feedback is welcomed.

BTW, adding a provider needs a careful decision and basically you won't expect someone else to make it.