A community plugin for Vendure E-Commerce that allows authentication with your Vendure server via client-side tokens, issued from Google or Facebook.
- Prerequisites
- Installation
- Configuration
- GraphQL Extensions
- Entities
- Admin UI Extensions
- Error Handling
- License
Vendure Social Auth uses authentication tokens, issued on the client using the Google Sign-In SDK or the Facebook Javascript SDK. On the frontend, you have to guide the user through your application's authentication process, get their consent, and retrieve an access token before you can pass it to the plugin.
-
If you haven't already, create your server as described in Vendure's official docs
npm install @glarus-labs/vendure-social-auth
yarn add @glarus-labs/vendure-social-auth
- In your
vendure-config.ts
file, initialize theSocialAuthPlugin
plugin inside theVendureConfig
object's plugin array:
import { SocialAuthPlugin } from '@glarus-labs/vendure-social-auth';
export const config: VendureConfig = {
plugins: [
SocialAuthPlugin.init({
google: {
strategyName: 'google',
clientId: 'xxxx'
},
facebook: {
strategyName: 'facebook',
apiVersion: 'v6.0',
appId: 'xxxx',
appSecret: 'xxxx',
}
})
]
}
The plugin's init
function is configured using the SocialAuthPluginOptions
interface:
export interface SocialAuthPluginOptions {
google: {
/** The Google strategy name your resolver will expect.
* Optional. Default value: 'google'
*/
strategyName?: string;
/** The client id issued by your Google application. */
clientId: string;
},
facebook: {
/** The Facebook strategy name your resolver will expect.
* Optional. Default value: 'facebook'
*/
strategyName?: string;
/** The Facebook GraphAPI version the plugin will use.
* Format: 'vX.X'
* Optional. Default value: 'v6.0'
*/
apiVersion?: string;
/** The app id issued by your Facebook application. */
appId: string;
/** The app secret issued by your Facebook application. */
appSecret: string;
}
}
The current version of Vendure Social Auth extends the existing schema with a new mutation:
loginExternal(strategy: String!, token: String!): LoginResult!
The resolver for this mutation verifies the received token's validity with Google and Facebook's servers, and checks the database for a User with an identifier, matching the token. A new User - Customer pair is created, if a match is not found. An authenticated Session is created for the user.
Parameters:
- strategy - String! - Depending on the type of social login (Google or Facebook), pass one of the strategy name you defined in the plugin Configuration.
- token - String! - The token you received after completing the Prerequisites
Return type: LoginResult!
The current version of Vendure Social Auth does not include new entities or updates to existing ones.
The current version of Vendure Social Auth does not include Admin UI extensions.
// TODO
Vendure Social Auth is licensed under the MIT license.
Copyright © 2020, FlushBG