Azure DevOps プロバイダー
⚠️
非推奨 - まだ利用可能ですが、Microsoft は Azure DevOps OAuth を サポートしなくなっており、代わりに Microsoft Entra ID を使用することを推奨しています。
リソース
セットアップ
コールバックURL
https://example.com/api/auth/callback/azure-devops
環境変数
.env.local
に次のエントリを作成します
AZURE_DEVOPS_APP_ID=<copy App ID value here>
AZURE_DEVOPS_CLIENT_SECRET=<copy generated client secret value here>
アプリケーションの登録
https://app.vsaex.visualstudio.com/app/register
必要な詳細を入力します
- 会社名
- アプリケーション名
- アプリケーションのウェブサイト
- 認証コールバックURL
- 本番環境の場合は
https://example.com/api/auth/callback/azure-devops
- 開発環境の場合は
https://#/api/auth/callback/azure-devops
- 本番環境の場合は
- 承認されたスコープ
- 必要な最小限のスコープは
ユーザー プロファイル (読み取り)
です
- 必要な最小限のスコープは
「アプリケーションの作成」をクリック
⚠️
-
localhost であっても HTTPS を使用する必要があります
-
後でスコープを変更するには、アプリケーションを削除して新しく作成する必要があります
次のデータは次のステップに関連します
- アプリID
- クライアントシークレット(「表示」ボタンをクリックした後、その上のアプリシークレットエントリは無視してください)
- 承認されたスコープ
構成
/auth.ts
import NextAuth from "next-auth"
import AzureDevOps from "next-auth/providers/azure-devops"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
AzureDevOps({
clientId: AUTH_AZURE_DEVOPS_APP_ID,
clientSecret: AUTH_AZURE_DEVOPS_CLIENT_SECRET,
}),
],
})
リフレッシュトークンのローテーション
開始点として メインガイド を使用し、以下の点を考慮してください
./auth.ts
export const { signIn, signOut, auth } = NextAuth({
callbacks: {
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: 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
}