providers/bungie
default()
default(options): OAuthConfig<Record<string, any>>
ページにBungieログインを追加します。
セットアップ
コールバックURL
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はウェブサイトのURLとしてlocalhostを使用することを許可していません。代わりに、https://127.0.0.1:3000を使用する必要があります。
https://www.bungie.net/en/Application にアクセスし、必要な詳細情報を入力してください。
- アプリケーション名
- アプリケーションステータス
- ウェブサイト
- OAuthクライアントタイプ
- 機密
- リダイレクトURL
- スコープ
Bungie.netの通知、メンバーシップ、最近のBungie.Netフォーラムアクティビティなどのアイテムにアクセスします。
- オリジンヘッダー
以下のガイドが役立つ場合があります
#@example server
ホストファイルを編集し、サイトを 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
証明書の作成
localhostの証明書はopensslで簡単に作成できます。ターミナルに次のコマンドを入力してください。出力はlocalhost.keyとlocalhost.crtの2つのファイルになります。
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://localhost:3000")
})
})
注記
デフォルトでは、Auth.jsはBungieプロバイダーがOAuth 2仕様に基づいていると想定しています。
Bungieプロバイダーにはデフォルト設定が付属しています。ユースケースに合わせてデフォルトをオーバーライドするには、組み込みOAuthプロバイダーのカスタマイズを参照してください。
パラメーター
パラメーター | 型 |
---|---|
オプション | OAuthUserConfig <Record <string , any >> |
戻り値
OAuthConfig
<Record
<string
, any
>>