providers/azure-devops
AzureDevOpsProfile
請參閱
Azure DevOps Services REST API 7.0 · Profiles · Get
繼承
Record
<string
,any
>
屬性
coreAttributes
coreAttributes: {
Avatar: {
value: {
value: string;
};
};
};
Avatar
Avatar: {
value: {
value: string;
};
};
Avatar.value
value: {
value: string;
};
Avatar.value.value
value: string;
displayName
displayName: string;
emailAddress
emailAddress: string;
id
id: string;
default()
default<P>(options): OAuthConfig<P>
類型參數
類型參數 |
---|
P extends AzureDevOpsProfile |
參數
參數 | 類型 |
---|---|
options | OAuthUserConfig <P > & { scope : string ; } |
返回值
OAuthConfig
<P
>
已棄用
雖然仍然可用,但 Microsoft 不再支援 Azure DevOps OAuth,並建議改用 Microsoft Entra ID。
文件
Microsoft 文件 · Azure DevOps · 使用 OAuth 2.0 授權存取 REST API
設定
註冊應用程式
提供必要的詳細資訊
- 公司名稱
- 應用程式名稱
- 應用程式網站
- 授權回調 URL
https://example.com/api/auth/callback/azure-devops
用於生產環境https://127.0.0.1/api/auth/callback/azure-devops
用於開發環境
- 授權範圍
- 要求的最低限度是
使用者個人資料 (讀取)
- 要求的最低限度是
點擊「建立應用程式」
⚠️
即使是 localhost,您也必須使用 HTTPS
⚠️
您必須刪除並建立新的應用程式才能稍後變更範圍
以下資料與下一步相關
- 應用程式 ID
- 客戶端密碼(在點擊「顯示」按鈕後,忽略上方應用程式密碼條目)
- 授權範圍
設定環境變數
在 .env.local
中建立以下條目
AZURE_DEVOPS_APP_ID=<copy App ID value here>
AZURE_DEVOPS_CLIENT_SECRET=<copy generated client secret value here>
AZURE_DEVOPS_SCOPE=<copy space separated Authorized Scopes list here>
範例
import AzureDevOps from "@auth/core/providers/azure-devops"
...
providers: [
AzureDevOps({
clientId: process.env.AZURE_DEVOPS_APP_ID,
clientSecret: process.env.AZURE_DEVOPS_CLIENT_SECRET,
scope: process.env.AZURE_DEVOPS_SCOPE,
}),
]
...
更新令牌輪換
請使用主要指南作為起點,並考量以下事項
async jwt({ token, user, account }) {
...
// The token has an absolute expiration time
const accessTokenExpires = account.expires_at * 1000
...
}
async function refreshAccessToken(token) {
...
const response = await fetch(
"https://app.vssps.visualstudio.com/oauth2/token",
{
headers: { "Content-Type": "application/x-www-form-urlencoded" },
method: "POST",
body: new URLSearchParams({
client_assertion_type:
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
client_assertion: process.env.AZURE_DEVOPS_CLIENT_SECRET,
grant_type: "refresh_token",
assertion: token.refreshToken,
redirect_uri:
process.env.NEXTAUTH_URL + "/api/auth/callback/azure-devops",
}),
}
)
...
// The refreshed token comes with a relative expiration time
const accessTokenExpires = Date.now() + newToken.expires_in * 1000
...
}