|
| 1 | +--- |
| 2 | +id: bungie |
| 3 | +title: Bungie |
| 4 | +--- |
| 5 | + |
| 6 | +## Documentation |
| 7 | + |
| 8 | +https://github.com/Bungie-net/api/wiki/OAuth-Documentation |
| 9 | + |
| 10 | +## Configuration |
| 11 | + |
| 12 | +https://www.bungie.net/en/Application |
| 13 | + |
| 14 | +## Example |
| 15 | + |
| 16 | +```js |
| 17 | +import Providers from `next-auth/providers` |
| 18 | +... |
| 19 | +providers: [ |
| 20 | + Providers.Bungie({ |
| 21 | + clientId: process.env.BUNGIE_CLIENT_ID, |
| 22 | + clientSecret: process.env.BUNGIE_SECRET, |
| 23 | + apiKey: process.env.BUNGIE_API_KEY |
| 24 | + }), |
| 25 | +} |
| 26 | +... |
| 27 | +``` |
| 28 | + |
| 29 | +## Instructions |
| 30 | + |
| 31 | +### Configuration |
| 32 | + |
| 33 | +:::tip |
| 34 | +Bungie require all sites to run HTTPS (including local development instances). |
| 35 | +::: |
| 36 | + |
| 37 | +:::tip |
| 38 | +Bungie doesn't allow you to use localhost as the website URL, instead you need to use https://127.0.0.1:3000 |
| 39 | +::: |
| 40 | + |
| 41 | +Navigate to https://www.bungie.net/en/Application and fill in the required details: |
| 42 | + |
| 43 | +* Application name |
| 44 | +* Application Status |
| 45 | +* Website |
| 46 | +* OAuth Client Type |
| 47 | + - Confidential |
| 48 | +* Redirect URL |
| 49 | + - https://localhost:3000/api/auth/callback/bungie |
| 50 | +* Scope |
| 51 | + - `Access items like your Bungie.net notifications, memberships, and recent Bungie.Net forum activity.` |
| 52 | +* Origin Header |
| 53 | + |
| 54 | +The following guide may be helpful: |
| 55 | + |
| 56 | +* [How to setup localhost with HTTPS with a Next.js app](https://medium.com/@anMagpie/secure-your-local-development-server-with-https-next-js-81ac6b8b3d68) |
| 57 | + |
| 58 | +### Example server |
| 59 | + |
| 60 | +You will need to edit your host file and point your site at `127.0.0.1` |
| 61 | + |
| 62 | +[How to edit my host file?](https://phoenixnap.com/kb/how-to-edit-hosts-file-in-windows-mac-or-linux) |
| 63 | + |
| 64 | +On Windows (Run Powershell as administrator) |
| 65 | + |
| 66 | +```ps |
| 67 | +Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1`tdev.example.com" -Force |
| 68 | +``` |
| 69 | + |
| 70 | +``` |
| 71 | +127.0.0.1 dev.example.com |
| 72 | +``` |
| 73 | + |
| 74 | +#### Create certificate |
| 75 | + |
| 76 | + |
| 77 | +Creating a certificate for localhost is easy with openssl . Just put the following command in the terminal. The output will be two files: localhost.key and localhost.crt. |
| 78 | + |
| 79 | +```bash |
| 80 | +openssl req -x509 -out localhost.crt -keyout localhost.key \ |
| 81 | + -newkey rsa:2048 -nodes -sha256 \ |
| 82 | + -subj '/CN=localhost' -extensions EXT -config <( \ |
| 83 | + printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth") |
| 84 | +``` |
| 85 | + |
| 86 | +:::tip |
| 87 | +**Windows** |
| 88 | + |
| 89 | +The OpenSSL executable is distributed with [Git](https://git-scm.com/download/win]9) for Windows. |
| 90 | +Once installed you will find the openssl.exe file in `C:/Program Files/Git/mingw64/bin` which you can add to the system PATH environment variable if it’s not already done. |
| 91 | + |
| 92 | +Add environment variable `OPENSSL_CONF=C:/Program Files/Git/mingw64/ssl/openssl.cnf` |
| 93 | + |
| 94 | +```bash |
| 95 | + req -x509 -out localhost.crt -keyout localhost.key \ |
| 96 | + -newkey rsa:2048 -nodes -sha256 \ |
| 97 | + -subj '/CN=localhost' |
| 98 | +``` |
| 99 | + |
| 100 | +::: |
| 101 | + |
| 102 | +Create directory `certificates` and place `localhost.key` and `localhost.crt` |
| 103 | + |
| 104 | + |
| 105 | +You can create a `server.js` in the root of your project and run it with `node server.js` to test Sign in with Bungie integration locally: |
| 106 | + |
| 107 | + |
| 108 | +```js |
| 109 | +const { createServer } = require('https') |
| 110 | +const { parse } = require('url') |
| 111 | +const next = require('next') |
| 112 | +const fs = require('fs') |
| 113 | + |
| 114 | +const dev = process.env.NODE_ENV !== 'production' |
| 115 | +const app = next({ dev }) |
| 116 | +const handle = app.getRequestHandler() |
| 117 | + |
| 118 | +const httpsOptions = { |
| 119 | + key: fs.readFileSync('./certificates/localhost.key'), |
| 120 | + cert: fs.readFileSync('./certificates/localhost.crt') |
| 121 | +} |
| 122 | + |
| 123 | +app.prepare().then(() => { |
| 124 | + createServer(httpsOptions, (req, res) => { |
| 125 | + const parsedUrl = parse(req.url, true) |
| 126 | + handle(req, res, parsedUrl) |
| 127 | + }).listen(3000, err => { |
| 128 | + if (err) throw err |
| 129 | + console.log('> Ready on https://localhost:3000') |
| 130 | + }) |
| 131 | +}) |
| 132 | +``` |
0 commit comments