Skip to content

Commit 8a121ba

Browse files
committed
add authentication to auth.mapping.team
1 parent e8cf103 commit 8a121ba

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
import NextAuth from 'next-auth'
22

3-
export const authOptions = {
3+
export default NextAuth({
4+
// Configure one or more authentication providers
45
providers: [
56
{
6-
id: 'openstreetmap',
7-
name: 'openstreetmap',
8-
clientId: process.env.OSM_CONSUMER_KEY,
9-
clientSecret: process.env.OSM_CONSUMER_SECRET,
7+
id: 'osm-teams',
8+
name: 'OSM Teams',
109
type: 'oauth',
11-
authorization: {
12-
url: 'https://www.openstreetmap.org/oauth2/authorize',
13-
params: {
14-
scope: 'read_prefs',
15-
},
16-
},
17-
token: 'https://www.openstreetmap.org/oauth2/token',
18-
userinfo: 'https://api.openstreetmap.org/api/0.6/user/details.json',
19-
profile({ user }) {
10+
wellKnown:
11+
'https://auth.mapping.team/hyauth/.well-known/openid-configuration',
12+
authorization: { params: { scope: 'openid offline' } },
13+
idToken: true,
14+
async profile(profile) {
2015
return {
21-
id: user.id,
22-
name: user.display_name,
23-
image: user.img?.href,
16+
id: profile.sub,
17+
name: profile.preferred_username,
18+
image: profile.picture,
2419
}
2520
},
21+
clientId: process.env.OSM_TEAMS_CLIENT_ID,
22+
clientSecret: process.env.OSM_TEAMS_CLIENT_SECRET,
2623
},
2724
],
2825
callbacks: {
26+
async jwt({ token, account, profile }) {
27+
// Persist the OAuth access_token and or the user id to the token right after signin
28+
if (account) {
29+
token.accessToken = account.access_token
30+
token.userId = profile.sub
31+
}
32+
return token
33+
},
2934
async session({ session, token }) {
30-
// Add user id to session
31-
const userId = parseInt(token.sub)
32-
session.user_id = userId
35+
// Send properties to the client, like an access_token and user id from a provider.
36+
session.accessToken = token.accessToken
37+
session.user_id = token.userId
3338
return session
3439
},
3540
},
36-
}
37-
38-
export default NextAuth(authOptions)
41+
// A database is optional, but required to persist accounts in a database
42+
database: process.env.DATABASE_URL,
43+
})

0 commit comments

Comments
 (0)