ข้ามไปยังเนื้อหาหลัก

Custom OAuth

หมายเหตุ

Casdoor รองรับผู้ให้บริการแบบกำหนดเอง อย่างไรก็ตาม ผู้ให้บริการแบบกำหนดเองต้องปฏิบัติตามกระบวนการมาตรฐานของ OAuth 3-legged และค่าที่ส่งกลับของ Token URL และ UserInfo URL ต้องสอดคล้องกับรูปแบบที่ Casdoor กำหนด

Overview

Custom OAuth providers allow you to integrate any OAuth 2.0 compliant authentication service with Casdoor, even if it's not officially supported. This is useful when you want to integrate with:

  • Internal enterprise OAuth servers
  • Self-hosted authentication systems
  • Third-party services not yet officially supported by Casdoor

Multiple Custom Providers Support

Casdoor supports up to 10 different custom OAuth providers simultaneously. When creating custom providers, you can choose from the following types:

  • Custom - The first custom provider
  • Custom2 through Custom10 - Additional custom providers

This allows you to integrate multiple custom OAuth services without conflicts. Each custom provider maintains its own separate configuration and user data fields.

Creating a Custom Provider

To create a new custom provider, navigate to the provider page of Casdoor, and select one of the custom types ("Custom", "Custom2", "Custom3", etc.) in the Type field. จากนั้นคุณจะต้องกรอก Client ID, Client Secret, Auth URL, Scope,Token URL, UserInfo URL, และ Favicon

image-20220418100744005

  • Auth URL เป็นที่อยู่หน้าเว็บ OAuth สำหรับการเข้าสู่ระบบของผู้ให้บริการแบบกำหนดเอง

    หากคุณกรอก https://door.casdoor.com/login/oauth/authorize เป็น Auth URL แล้ว เมื่อผู้ใช้เข้าสู่ระบบด้วยผู้ให้บริการแบบกำหนดเองนี้ เบราว์เซอร์จะเปลี่ยนเส้นทางไปยัง

    https://door.casdoor.com/login/oauth/authorize?client_id={ClientID}&redirect_uri=https://{your-casdoor-hostname}/callback&state={State_generated_by_Casdoor}&response_type=code&scope={Scope} 

    หลังจากที่การอนุญาตเสร็จสิ้นแล้ว ผู้ให้บริการแบบกำหนดเองควรเปลี่ยนเส้นทางไปยัง

    https://{your-casdoor-hostname}/callback?code={code}

    หลังจากขั้นตอนนี้ Casdoor จะรู้จักพารามิเตอร์ code ใน URL

  • Scope เป็นพารามิเตอร์ scope ที่ใช้เมื่อเข้าถึง Auth URL และคุณควรกรอกตามที่ผู้ให้บริการแบบกำหนดเองกำหนด

  • Token URL เป็นจุดสิ้นสุด API สำหรับการรับ accessToken

    เมื่อคุณได้รับ code ในขั้นตอนก่อนหน้านี้ Casdoor ควรใช้มันเพื่อรับ accessToken

    หากคุณกรอก https://door.casdoor.com/api/login/oauth/access_token เป็น Token URL แล้ว Casdoor จะเข้าถึงมันโดยใช้คำสั่งต่อไปนี้

    curl -X POST -u "{ClientID}:{ClientSecret}" --data-binary "code={code}&grant_type=authorization_code&redirect_uri=https://{your-casdoor-hostname}/callback" https://door.casdoor.com/api/login/oauth/access_token

    ผู้ให้บริการแบบกำหนดเองควรส่งคืนข้อมูลอย่างน้อยต่อไปนี้:

    {
    "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ixxxxxxxxxxxxxx",
    "refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6xxxxxxxxxxxxxx",
    "token_type": "Bearer",
    "expires_in": 10080,
    "scope": "openid profile email"
    }
  • UserInfo URL เป็นจุดสิ้นสุด API สำหรับการรับข้อมูลผู้ใช้ผ่าน accessToken

    หากคุณกรอก https://door.casdoor.com/api/userinfo เป็น UserInfo URL แล้ว Casdoor จะเข้าถึงมันโดยใช้คำสั่งต่อไปนี้

    curl -X GET -H "Authorization: Bearer {accessToken}" https://door.casdoor.com/api/userinfo

    ผู้ให้บริการแบบกำหนดเองควรส่งคืนข้อมูลอย่างน้อยต่อไปนี้:

    {
    "name": "admin",
    "preferred_username": "Admin",
    "email": "admin@example.com",
    "picture": "https://casbin.org/img/casbin.svg"
    }
  • Favicon เป็น URL ของโลโก้สำหรับผู้ให้บริการแบบกำหนดเอง

    โลโก้นี้จะถูกแสดงบนหน้าเข้าสู่ระบบของ Casdoor ร่วมกับผู้ให้บริการเข้าสู่ระบบบุคคลที่สามอื่นๆ