Skip to content

Commit afe69b7

Browse files
authored
feat: Add Epic Games configuration (#165)
* feat: Add Epic Games configuration * fix: listen on correct port
1 parent 9f7392d commit afe69b7

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ You can choose some default setup to assign to `auth` option.
6565
- `TWITCH_CONFIGURATION`
6666
- `VATSIM_CONFIGURATION`
6767
- `VATSIM_DEV_CONFIGURATION`
68+
- `EPIC_GAMES_CONFIGURATION`
6869

6970
### Custom configuration
7071

examples/epic-games.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fastify = require('fastify')({ logger: { level: 'trace' } })
2+
3+
// const oauthPlugin = require('fastify-oauth2')
4+
const oauthPlugin = require('..')
5+
6+
fastify.register(oauthPlugin, {
7+
name: 'egOAuth2',
8+
scope: ['basic_profile'], // 'basic_profile', 'friends_list', 'presence',
9+
credentials: {
10+
client: {
11+
id: process.env.CLIENT_ID,
12+
secret: process.env.CLIENT_SECRET
13+
},
14+
auth: oauthPlugin.EPIC_GAMES_CONFIGURATION
15+
},
16+
startRedirectPath: '/login/eg',
17+
callbackUri: `http://localhost:${process.env.PORT}/login/eg/callback`
18+
})
19+
20+
fastify.get('/login/eg/callback', async (req, reply) => {
21+
const token = await fastify.egOAuth2.getAccessTokenFromAuthorizationCodeFlow(req)
22+
23+
req.log.info('The Epic Games token is %o', token)
24+
reply.send({ access_token: token.access_token })
25+
})
26+
27+
fastify.listen(process.env.PORT, (err, address) => {
28+
if (err) {
29+
fastify.log.error(err)
30+
process.exit(1)
31+
}
32+
fastify.log.info(`server listening on ${address}`)
33+
})

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface FastifyOAuth2 {
1313
TWITCH_CONFIGURATION: ProviderConfiguration;
1414
VATSIM_CONFIGURATION: ProviderConfiguration;
1515
VATSIM_DEV_CONFIGURATION: ProviderConfiguration;
16+
EPIC_GAMES_CONFIGURATION: ProviderConfiguration;
1617
}
1718

1819
export const fastifyOauth2: FastifyPluginCallback<FastifyOAuth2Options> & FastifyOAuth2

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,11 @@ oauthPlugin.VATSIM_DEV_CONFIGURATION = {
251251
tokenPath: '/oauth/token'
252252
}
253253

254+
oauthPlugin.EPIC_GAMES_CONFIGURATION = {
255+
authorizeHost: 'https://www.epicgames.com',
256+
authorizePath: '/id/authorize',
257+
tokenHost: 'https://api.epicgames.dev',
258+
tokenPath: '/epic/oauth/v1/token'
259+
}
260+
254261
module.exports = oauthPlugin

test/types/index.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ expectAssignable<ProviderConfiguration>(fastifyOauth2.VKONTAKTE_CONFIGURATION);
5959
expectAssignable<ProviderConfiguration>(fastifyOauth2.TWITCH_CONFIGURATION);
6060
expectAssignable<ProviderConfiguration>(fastifyOauth2.VATSIM_CONFIGURATION);
6161
expectAssignable<ProviderConfiguration>(fastifyOauth2.VATSIM_DEV_CONFIGURATION);
62+
expectAssignable<ProviderConfiguration>(fastifyOauth2.EPIC_GAMES_CONFIGURATION);
6263

6364
server.get('/testOauth/callback', async request => {
6465
expectType<OAuth2Namespace>(server.testOAuthName);

0 commit comments

Comments
 (0)