跳至內容
正在從 NextAuth.js v4 遷移?請閱讀 我們的遷移指南.

providers/bungie

內建 Bungie 整合。

default()

default(options): OAuthConfig<Record<string, any>>

將 Bungie 登入新增至您的頁面。

設定

回調網址

https://example.com/api/auth/callback/bungie

設定

import { Auth } from "@auth/core"
import Bungie from "@auth/core/providers/bungie"
 
const request = new Request(origin)
const response = await Auth(request, {
  providers: [
    Bungie({
      clientId: BUNGIE_CLIENT_ID,
      clientSecret: BUNGIE_CLIENT_SECRET,
      headers: { "X-API-Key": BUNGIE_API_KEY },
    }),
  ],
})

資源

設定

💡

Bungie 要求所有網站都必須以 HTTPS 執行(包括本地開發執行個體)。

💡

Bungie 不允許您使用 localhost 作為網站網址,而是需要使用 https://127.0.0.1:3000

前往 https://www.bungie.net/en/Application 並填寫必要的詳細資料

  • 應用程式名稱
  • 應用程式狀態
  • 網站
  • OAuth 用戶端類型
    • 機密
  • 重新導向網址
  • 範圍
    • 存取您的 Bungie.net 通知、會員資格和最近的 Bungie.net 論壇活動等項目。
  • 來源標頭

以下指南可能會有幫助

#@example server

您需要編輯您的 host 檔案,並將您的網站指向 127.0.0.1

如何編輯我的 host 檔案?

在 Windows 上(以管理員身分執行 PowerShell)

Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1`tdev.example.com" -Force
127.0.0.1 dev.example.com

建立憑證

使用 openssl 輕鬆為 localhost 建立憑證。只需在終端機中輸入以下命令即可。輸出將是兩個檔案:localhost.key 和 localhost.crt。

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj "/CN=localhost" -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
💡

Windows

OpenSSL 可執行檔隨附於適用於 Windows 的 Git。安裝後,您將在 C:/Program Files/Git/mingw64/bin 中找到 openssl.exe 檔案,如果尚未完成,您可以將其新增至系統 PATH 環境變數。

新增環境變數 OPENSSL_CONF=C:/Program Files/Git/mingw64/ssl/openssl.cnf

 req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj "/CN=localhost"

建立目錄 certificates 並放置 localhost.keylocalhost.crt

您可以在專案的根目錄中建立一個 server.js,並使用 node server.js 來執行,以在本地測試使用 Bungie 登入整合

const { createServer } = require("https")
const { parse } = require("url")
const next = require("next")
const fs = require("fs")
 
const dev = process.env.NODE_ENV !== "production"
const app = next({ dev })
const handle = app.getRequestHandler()
 
const httpsOptions = {
  key: fs.readFileSync("./certificates/localhost.key"),
  cert: fs.readFileSync("./certificates/localhost.crt"),
}
 
app.prepare().then(() => {
  createServer(httpsOptions, (req, res) => {
    const parsedUrl = parse(req.url, true)
    handle(req, res, parsedUrl)
  }).listen(3000, (err) => {
    if (err) throw err
    console.log("> Ready on https://127.0.0.1:3000")
  })
})

注意事項

預設情況下,Auth.js 假設 Bungie 提供者是基於 OAuth 2 規格。

💡

Bungie 提供者隨附 預設設定。若要覆寫您的用例的預設值,請查看自訂內建的 OAuth 提供者

免責聲明 如果您認為在預設設定中發現錯誤,您可以開啟問題

Auth.js 嚴格遵守規格,並且不對提供者的規格偏差負責。您可以開啟問題,但如果問題是不符合規格,我們可能不會尋求解決方案。您可以在討論中尋求更多幫助。

參數

參數類型
選項OAuthUserConfig<Record<string, any>>

返回

OAuthConfig<Record<string, any>>

Auth.js © Balázs Orbán 與團隊 -2024