Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

jxnkwlp/AspNetCore.AuthenticationQQ-WebChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic config OAuth client

see this .

OAuth 动态配置

传送门 .

Microsoft.AspNetCore.Authentication Extensions

QQ and Webchat extensions for Microsoft.AspNetCore.Authentication

Get Started

dotnet core 2.0

  • Install nuget package

    WebChat

    PM> Install-Package Passingwind.AspNetCore.Authentication.Weixin
    

    QQ

    PM> Install-Package Passingwind.AspNetCore.Authentication.QQ
    
  • QQ

 // startup.cs 
public void ConfigureServices(IServiceCollection services)
{
    // .... others code ...
    // config 
    services.AddAuthentication() 
        .AddQQAuthentication(options =>
        {
            options.ClientId = "[you app id]";
            options.ClientSecret = "[you app secret]";
        });

    // .... others code ...
}

Then get current external login information when login success . eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... others code ...
    // .....
  
    // get information from HttpContext (using Microsoft.AspNetCore.Authentication.QQ;)
    var loginInfo = await HttpContext.GetExternalQQLoginInfoAsync();
    
    // todo ...
    // .... others code ...
} 
  • WebChat
 // startup.cs 
public void ConfigureServices(IServiceCollection services)
{
    // .... others code ...
    // config 
    services.AddAuthentication() 
        .AddWeixinAuthentication(options =>
        {
            options.ClientId = "[you app id]";
            options.ClientSecret = "[you app secret]";
        });

    // .... others code ...
}

Then get current external login information when login success . eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... others code ...
    // .....
  
    // get information from HttpContext (using Microsoft.AspNetCore.Authentication.Weixin;)
    var loginInfo = await HttpContext.GetExternalWeixinLoginInfoAsync();
    
    // todo ...
    // .... others code ...
}

dotnet core 1.1

  • QQ
 // startup.cs 
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // config 
    app.UseQQAuthentication(new Microsoft.AspNetCore.Authentication.QQ.QQAuthenticationOptions()
            {
                ClientId = "[you client id]",
                ClientSecret ="[you client Secret]",
            });

    // .... others code ...
}

Then get external login information when login success . eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... others code ...
    // .....
  
    // get information from AuthenticationManager (using Microsoft.AspNetCore.Authentication.QQ;)
    var loginInfo = await HttpContext.Authentication.GetExternalQQLoginInfoAsync();
    
    // todo ...
    // .... others code ...
}
  • Webchat
 // startup.cs 
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // config 
    app.UseWeixinAuthentication(new Microsoft.AspNetCore.Authentication.Weixin.WeixinAuthenticationOptions()
            {
                ClientId = "[you client id]",
                ClientSecret ="[you client Secret]",
            });

    // .... others code ...
}

Then get external login information when login success . eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... others code ...
    // .....
  
    // get information from AuthenticationManager (using Microsoft.AspNetCore.Authentication.Weixin;)
    var loginInfo = await HttpContext.Authentication.GetExternalWeixinLoginInfoAsync();
    
    // todo ...
    // .... others code ...
}

Microsoft.AspNetCore.Authentication 扩展

QQ 和 微信 Microsoft.AspNetCore.Authentication 扩展

使用方法

dotnet core 2.0

  • 安装 nuget 包

    微信

    PM> Install-Package Passingwind.AspNetCore.Authentication.Weixin
    

    QQ

    PM> Install-Package Passingwind.AspNetCore.Authentication.QQ
    
  • QQ

 // startup.cs 
public void ConfigureServices(IServiceCollection services)
{
    // .... others code ...
    // 配置 
    services.AddAuthentication() 
        .AddQQAuthentication(options =>
        {
            options.ClientId = "[you app id]";
            options.ClientSecret = "[you app secret]";
        });

    // .... others code ...
}

获取登陆成功后的信息。 eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... others code ...
    // .....
  
    // 获取登录者信息 (using Microsoft.AspNetCore.Authentication.QQ;)
    var loginInfo = await HttpContext.GetExternalQQLoginInfoAsync();

    // todo ...
    // .... others code ...
}
  • 微信
 // startup.cs 
public void ConfigureServices(IServiceCollection services)
{
    // .... others code ...
    // 配置 
    services.AddAuthentication() 
        .AddWeixinAuthentication(options =>
        {
            options.ClientId = "[you app id]";
            options.ClientSecret = "[you app secret]";
        });

    // .... others code ...
}

获取登陆成功后的信息。 eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... others code ...
    // .....
  
    // 获取登录者信息 (using Microsoft.AspNetCore.Authentication.Weixin;)
    var loginInfo = await HttpContext.GetExternalWeixinLoginInfoAsync();
    
    // todo ...
    // .... others code ...
}
 

dotnet core 1.1

  • QQ
 // startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // 配置 
    app.UseQQAuthentication(new Microsoft.AspNetCore.Authentication.QQ.QQAuthenticationOptions()
            {
                ClientId = "[you client id]",
                ClientSecret ="[you client Secret]",
            });

    // .... others code ...
}

获取登陆成功后的信息。 eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
    // .... others code ...
    // .....
  
    // 获取登录者信息 (using Microsoft.AspNetCore.Authentication.QQ;)
    var loginInfo = await HttpContext.Authentication.GetExternalQQLoginInfoAsync();

    // todo ...
    // .... others code ...
}
  • 微信
 // startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // 配置 
    app.UseWeixinAuthentication(new Microsoft.AspNetCore.Authentication.Weixin.WeixinAuthenticationOptions()
            {
                ClientId = "[you client id]",
                ClientSecret ="[you client Secret]",
            });

    // .... others code ...
}

获取登陆成功后的信息。 eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
    // .... others code ...
    // .....
  
    // 获取登录者信息 (using Microsoft.AspNetCore.Authentication.Weixin;)
    var loginInfo = await HttpContext.Authentication.GetExternalWeixinLoginInfoAsync();

    // todo ...
    // .... others code ...
}

About

QQ and Webchat extensions for Microsoft.AspNetCore.Authentication ( 1.1/2.0/3.0)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages