怎樣獲得『中央授權中心』的AccessToken

目錄

前期準備工作

【方式一】client_credentials模式

名稱、識別字 獲得 AccessToken
功能描述 根據 clientId 、secret 、scope 值 獲得 AccessToken
URL https://sso.foxconn.com/connect/token
Method POST  方法
Content Type application/x-www-form-URL encoded
Parameters client_id=[ClientID]&
client_secret=[密碼明文]&
grant_type=client_credentials &
scope=[權限范圍]
說明
  • client_id:您的  ClientID
  • client_secret:您的明文密碼
  • grant_type:此處固定為  client_credentials
  • scope:調用『中央授權中心』之外第三方接口權限對應的scope(如:civet.api.emp、email.api.find、c114.phone.ext)
Response Body {
    "access_token": "......",
    "expires_in": 3600,
    "token_type": "Bearer",
    "scope": "civet.api.emp c114.phone.ext"
}
補充說明 參考: https://sso.foxconn.com/Developer/Document/OIDC#token

【方式二】authorization_code模式

1.第一步:拼接生成OIDC授權鏈接跳轉登錄

涉及必填參數:

【例如】
調用Account/GetOne接口,系統要求必須包含Scope值 civet.api.emp 等

生成授權鏈接:
https://sso.foxconn.com/connect/authorize?client_id=[client_id]&scope=openid civet.api.emp&redirect_uri=https://[您的域名]/LoginBySso&response_type=code

訪問以上鏈接會跳轉到SSO登錄頁面,登錄成功後會攜帶參數scope和code值跳轉到重定向頁面,如下:
https://[您的域名]/LoginBySso?code=E385EC0C21EAB84D8E20F......

【參考文件】https://sso.foxconn.com/Developer/Document/OIDC#authorize

2. 通過第一步獲取的code  值獲取對應AccessToken  的接口

名稱、識別字 獲得  AccessToken
功能描述 根據 clientId 、secret 、code 值 獲得 AccessToken
URL https://sso.foxconn.com/connect/token
Method POST 方法
Content Type application/x-www-form-URL encoded
Parameters client_id=[ClientID]&
client_secret=[密碼明文 ]&
grant_type=authorization_code&
code=[code 值 ]&
redirect_uri=[重定向路徑 ]
說明
client_id:您的 ClientID
client_secret:您的明文密碼
grant_type:此處固定為 authorization_code
code:第一步登錄時獲取到的 code 值
redirect_uri:與第一步重定向路徑需一致
Response Body {     "access_token": "eyJhbGciOiJSUz.......",
    "token_type": "Bearer",
    "expires_in": 3600,
    "scope": "openid profile civet.api.emp"
}
說明
access_token:AccessToken
scope:在獲取token時加上offline_access,可以獲取RefreshToken。
expires_in:有效時間(秒),負責人可通過 https://sso.foxconn.com/developer 修改
補充說明 參考: https://sso.foxconn.com/Developer/Document/OIDC#token

3.若Token  過期時,刷新AccessToken (非必要,可以通過讓用戶重新登錄獲得新的TOKEN)

名稱、識別字 刷新  AccessToken
功能描述 使用  RefreshToken  刷新  AccessToken
URL https://sso.foxconn.com/connect/token
Method POST  方法
Content Type application/x-www-form-urlencoded
Parameters client_id=[ClientID]&
client_secret=[密碼明文]&
grant_type=refresh_token&
refresh_token=[RefreshToken]
說明
client_id  :您的  ClientID client_secret  :您的明文密碼 grant_type: 固定值為refresh_token refresh_token  :獲取access_token  時scope  包含offline_access  時返回的refresh_token  的值
Response Body {
    "access_token": "eyJhbGciOiJSUz.......",
    "expires_in": 3600,
    "token_type": "Bearer",
    "refresh_token": "2C1292A6133.......",
    "scope": "openid profile civet.api.emp offline_access"
}
說明
access_token :刷新的 AccessToken expires_in :有效時間(秒),負責人可通過 https://sso.foxconn.com/developer 修改
補充說明 參考:https://sso.foxconn.com/Developer/Document/OIDC#token

在線調試API