Code Monkey home page Code Monkey logo

externalloginmiddleware's Introduction

Microsoft.AspNetCore.Authentication Extensions

AspNetCore的 企业微信(WXWork)、阿里钉钉(DingTalk) 登录认证扩展

Get Started

  • 项目引用或安装nuget包
- WXWork   
~~~ json。配置信息
 //appsetting.json
 {
   //........其他配置
  "Authentication": {
    "WXWork": {
      "ClientId": "你的clientid(如果是供应商,填写供应商的corpid)",
      "ClientSecret":"你的clientsecret如果是供应商,填写供应商的ProviderSecret)"
    }
   }
  //........其他配置
 }

 
~~~ csharp
 // startup.cs 添加认证中间件
public void ConfigureServices(IServiceCollection services)
{
    // .... 其他代码 ...
    // config 
    services.AddAuthentication() 
        .AddWeixinAuthentication(options =>
        {
            options.ClientId = Configuration.GetValue<string>("Authentication:WXWork:ClientId");
            options.ClientSecret = Configuration.GetValue<string>("Authentication:Weixin:ClientSecret");
        });

    // .... 其他代码 ...
}

用户确认登录并登录成功,获取外部登录信息. eg: AccountController

// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{ 
    // .... 其他代码 ...
    // .....
  
    // 从HttpContext获取登录者信息 (using Microsoft.AspNetCore.Authentication.WXWork;)
    var loginInfo = await HttpContext.GetExternalWXWorkLoginInfoAsync();
    
    // todo ...
    // .... 其他代码 ...
}
 

本地调试需要使用内网穿透技术,可借助穿透工具frp,frp使用说明链接:http://blog.abcenter.xyz/?p=41 frp项目地址:https://github.com/fatedier/frp/blob/master/README_zh.md

externalloginmiddleware's People

Contributors

kiakaa avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.