providers/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
在 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.key
和 localhost.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 提供者。
參數
參數 | 類型 |
---|---|
選項 | OAuthUserConfig <Record <string , any >> |
返回
OAuthConfig
<Record
<string
, any
>>