QQ and Webchat extensions for Microsoft.AspNetCore.Authentication ( 1.1/2.0 )
Clone or download
Latest commit a8d2f77 Nov 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
netcore1.1 fix describe Sep 8, 2017
netcore2.0 update sample to core 2.1 and generate nuget package Nov 19, 2018
.gitattributes 添加 .gitignore 和 .gitattributes。 Aug 23, 2017
.gitignore 添加 .gitignore 和 .gitattributes。 Aug 23, 2017
OAuth2.txt 添加项目文件。 Aug 23, 2017
readme.md fix readme Nov 19, 2018

readme.md

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 ...
}