From 831c59dd5c272e25c53fff5456533db1a4e12544 Mon Sep 17 00:00:00 2001 From: Joe Bell Date: Sun, 6 Dec 2020 21:56:00 +0200 Subject: [PATCH] feat: add foursquare (#584) --- src/providers/foursquare.js | 22 +++++++++++++++++++++ src/providers/index.js | 2 ++ www/docs/configuration/providers.md | 3 ++- www/docs/faq.md | 2 +- www/docs/providers/foursquare.md | 30 +++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/providers/foursquare.js create mode 100644 www/docs/providers/foursquare.md diff --git a/src/providers/foursquare.js b/src/providers/foursquare.js new file mode 100644 index 0000000000..cf93a076ad --- /dev/null +++ b/src/providers/foursquare.js @@ -0,0 +1,22 @@ +export default ({ apiVersion, ...options }) => { + return { + id: 'foursquare', + name: 'Foursquare', + type: 'oauth', + version: '2.0', + params: { grant_type: 'authorization_code' }, + accessTokenUrl: 'https://foursquare.com/oauth2/access_token', + authorizationUrl: + 'https://foursquare.com/oauth2/authenticate?response_type=code', + profileUrl: `https://api.foursquare.com/v2/users/self?v=${apiVersion}`, + profile: (profile) => { + return { + id: profile.id, + name: `${profile.firstName} ${profile.lastName}`, + image: `${profile.prefix}original${profile.suffix}`, + email: profile.contact.email + } + }, + ...options + } +} diff --git a/src/providers/index.js b/src/providers/index.js index ace1e3f242..7bf13e2a42 100644 --- a/src/providers/index.js +++ b/src/providers/index.js @@ -10,6 +10,7 @@ import Cognito from './cognito' import Discord from './discord' import Email from './email' import Facebook from './facebook' +import Foursquare from './foursquare' import FusionAuth from './fusionauth' import GitHub from './github' import GitLab from './gitlab' @@ -38,6 +39,7 @@ export default { Discord, Email, Facebook, + Foursquare, FusionAuth, GitHub, GitLab, diff --git a/www/docs/configuration/providers.md b/www/docs/configuration/providers.md index b8635f71f3..c6de9373c4 100644 --- a/www/docs/configuration/providers.md +++ b/www/docs/configuration/providers.md @@ -20,6 +20,7 @@ NextAuth.js is designed to work with any OAuth service, it supports OAuth 1.0, 1 * [Amazon Cognito](/providers/cognito) * [Discord](/providers/discord) * [Facebook](/providers/facebook) +* [Foursquare](/providers/foursquare) * [FusionAuth](/providers/fusionauth) * [GitHub](/providers/github) * [GitLab](/providers/gitlab) @@ -104,7 +105,7 @@ As an example of what this looks like, this is the the provider object returned clientSecret: '' } ``` -You can replace all the options in this JSON object with the ones from your custom provider – be sure to give it a unique ID and specify the correct OAuth version - and add it to the providers option: +You can replace all the options in this JSON object with the ones from your custom provider – be sure to give it a unique ID and specify the correct OAuth version - and add it to the providers option: ```js title="pages/api/auth/[...nextauth].js" ... diff --git a/www/docs/faq.md b/www/docs/faq.md index a10344c8bc..729827127f 100644 --- a/www/docs/faq.md +++ b/www/docs/faq.md @@ -23,7 +23,7 @@ You can use also NextAuth.js with any database using a custom database adapter, ### What authentication services does NextAuth.js support? -NextAuth.js includes built-in support for signing in with Apple, Atlassian, Auth0, Google, Battle.net, Box, AWS Cognito, Discord, Facebook, FusionAuth, GitHub, GitLab, Google, Open ID Identity Server, Mixer, Netlify, Okta, Slack, Spotify, Twitch, Twitter and Yandex. +NextAuth.js includes built-in support for signing in with Apple, Atlassian, Auth0, Google, Battle.net, Box, AWS Cognito, Discord, Facebook, Foursquare, FusionAuth, GitHub, GitLab, Google, Open ID Identity Server, Mixer, Netlify, Okta, Slack, Spotify, Twitch, Twitter and Yandex. NextAuth.js also supports email for passwordless sign in, which is useful for account recovery or for people who are not able to use an account with the configured OAuth services (e.g. due to service outage, account suspension or otherwise becoming locked out of an account). diff --git a/www/docs/providers/foursquare.md b/www/docs/providers/foursquare.md new file mode 100644 index 0000000000..23d11eb684 --- /dev/null +++ b/www/docs/providers/foursquare.md @@ -0,0 +1,30 @@ +--- +id: foursquare +title: Foursquare +--- + +## Documentation + +https://developer.foursquare.com/docs/places-api/authentication/#web-applications + +## Configuration + +https://developer.foursquare.com/ + +:::warning +Foursquare requires an additional `apiVersion` parameter in [`YYYYMMDD` format](https://developer.foursquare.com/docs/places-api/versioning/), which essentially states "I'm prepared for API changes up to this date". + +## Example + +```js +import Providers from `next-auth/providers` +... +providers: [ + Providers.Foursquare({ + clientId: process.env.FOURSQUARE_CLIENT_ID, + clientSecret: process.env.FOURSQUARE_CLIENT_SECRET, + apiVersion: 'YYYYMMDD' + }) +} +... +```