コンテンツにスキップ
NextAuth.js v4 からの移行ですか?お読みください 移行ガイド.

providers/bungie

組み込みの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.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://localhost:3000")
  })
})

注記

デフォルトでは、Auth.jsはBungieプロバイダーがOAuth 2仕様に基づいていると想定しています。

💡

Bungieプロバイダーにはデフォルト設定が付属しています。ユースケースに合わせてデフォルトをオーバーライドするには、組み込みOAuthプロバイダーのカスタマイズを参照してください。

免責事項 デフォルト設定にバグが見つかったと思われる場合は、問題を開くことができます。

Auth.jsは仕様に厳密に従っており、プロバイダーによる仕様からの逸脱については責任を負いません。問題を開くことはできますが、問題が仕様に準拠していない場合、解決策を追求しない場合があります。ディスカッションでさらにヘルプを求めることができます。

パラメーター

パラメーター
オプションOAuthUserConfig<Record<string, any>>

戻り値

OAuthConfig<Record<string, any>>

Auth.js © Balázs Orbán and Team -2024