GithubHelp home page GithubHelp logo

yomansso5's Introduction

已支援的SSO

  • ✔️ Line
  • ✔️ FB
  • ✔️ Google
  • ✔️ LinkedIn
  • ✔️ MS

範例程式

Nuget下載網址

使用方式

  • 加入服務
    // 在Startup.cs檔的ConfigureServices Method加入以下程式
    
    // 讀取OAuth2 appsetting.json參數資料的Service
    SSOServiceCollections.AddSSOConfig (services);
    
    // Line相關的Service
    SSOServiceCollections.AddLine (services);
    
    // Facebook相關的Service
    SSOServiceCollections.AddFB (services);
    
    // Google相關的Service
    SSOServiceCollections.AddGoogle (services);
    
    // LinkedIn相關的Service
    SSOServiceCollections.AddLinkedIn (services);
    
    // Microsoft相關的Service
    SSOServiceCollections.AddMS (services);
    
  • 在所有的appsetting.json檔加入OAuth2應用程式的參數 (微軟需要再加上租用戶識別碼)
"Line": {
    "ClientID": "[Your Line App ClientID]",
    "ClientSecret": "[Your Line App ClientSecret]",
    "RedirectUrl": "[Your Line App Redirect Url]"
  },
  "FB": {
   "ClientID": "[Your FB App ClientID]",
    "ClientSecret": "[Your FB App ClientSecret]",
    "RedirectUrl": "[Your FB App Redirect Url]"
  },
  "Google": {
    "ClientID": "[Your Google App ClientID]",
    "ClientSecret": "[Your Google App ClientSecret]",
    "RedirectUrl": "[Your Google App Redirect Url]"
  },
  "LinkedIn": {
     "ClientID": "[Your LinkedIn App ClientID]",
    "ClientSecret": "[Your LinkedIn App ClientSecret]",
    "RedirectUrl": "[Your LinkedIn App Redirect Url]"
  },
  "MS": {
    "ClientID": "[Your Micorsoft App ClientID]",
    "TenantID": "[Your Micorsoft TenantID]",
    "ClientSecret": "[Your Micorsoft App ClientSecret]",
    "RedirectUrl": "[Your Micorsoft App Redirect Url]"
  }
  • 注入服務
        // Line
        private LineService _lineService ;
        // Facebook
        private FBService _fBService ;
        // Google
        private GoogleService _googleService ;
        // LinkedIn
        private LinkedInService _linkedService ;
        // Microsoft
        private MSService _msService;
        public HomeController ( LineService lineService, FBService fBService, GoogleService googleService, LinkedInService linkedService, MSService msService) {
            _lineService = lineService;
            _fBService = fBService;
            _googleService = googleService;
            _linkedService = linkedService;
            _msService = msService;
        }
  • 取得OAuth2 登入畫面網址
// Line OAuth2 登入畫面網址
string LineAccessUrl = await _lineService.GetAccessUrl ();
// Facebook OAuth2 登入畫面網址
string FBAccessUrl = await _fBService.GetAccessUrl ();
// Google OAuth2 登入畫面網址
string GoogelAccessUrl = await _googleService.GetAccessUrl ();
// LinkedIn OAuth2 登入畫面網址
string LinkedAccessUrl = await _linkedService.GetAccessUrl ();
// Microsoft OAuth2 登入畫面網址
string MSAccessUrl = await _msService.GetAccessUrl ();
  • 取得AccessToken和使用者資料
// Line 
// 授權碼
string LineAuthorizeCode="12312312vvvv";
// AccessToken
var LineAccessToken = await _lineService.GetAccessToken (LineAuthorizeCode);
// Line使用者資料
var LineUserProfile=await _lineService.GetProfile (LineAccessToken);
// Line使用者Email
var LineUserEmail=await _lineService.GetEmail(LineAccessToken);

// LinkedIn
// 授權碼
string LinkedInAuthorizeCode="@#$%";
// AccessToken
var LinkedInAccessToken = await _linkedInService.GetAccessToken (LinkedInAuthorizeCode);
// LinkedIn使用者資料
var LinkedInUserProfile=await _linkedInService.GetProfile (LinkedInAccessToken);

// Microsoft
// 授權碼
string MSAuthorizeCode="12312312vvvv";
var MSAccessToken = await _msService.GetAccessToken (MSAuthorizeCode);
// Microsoft使用者資料
var MSleUserProfile=await _msService.GetProfile (MSAccessToken);

// Google
// 授權碼
string GoogleAuthorizeCode="POIJH00";
// AccessToken
var GoogleAccessToken = await _googleService.GetAccessToken (GoogleAuthorizeCode);
// Google使用者資料
var GoogleUserProfile=await _googleService.GetProfile (GoogleAccessToken);

// Facebook
// 授權碼
string FBAuthorizeCode="%^&*";
// AccessToken
var FBAccessToken = await _fBService.GetAccessToken (FBAuthorizeCode);
// Facebook使用者資料
var FBUserProfile=await _fBService.GetProfile (FBAccessToken);

TODO

  • 客製化Scope參數
  • 回傳客製化錯誤訊息

yomansso5's People

Contributors

benknightdark avatar

Watchers

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