passport-square-oauth2
Version:
Passport provider for Square OAuth 2
61 lines (60 loc) • 2.9 kB
TypeScript
import OAuth2Strategy from 'passport-oauth2';
import { StrategyOptions as SquareStrategyOptions, VerifyFunction } from './types';
/**
* `Strategy` constructor.
*
* The Square authentication strategy authenticates requests by delegating to
* Square using the OAuth 2.0 protocol.
*
* Applications must supply a `verify` callback which accepts an `accessToken`,
* `refreshToken` and service-specific `profile`, and then calls the `done`
* callback supplying a `user`, which should be set to `false` if the
* credentials are not valid. If an exception occurred, `err` should be set.
*
* Options:
* - `clientId` your Square application's client id
* - `clientSecret` your Square application's client secret
* - `callbackURL` URL to which Square will redirect the user after granting authorization (optional of set in your Square Application
* - `grant_type` Must be authorization_code
* - `userProfileURL` URL from with the user profile will be fetched, a `/v1/merchants/me` endpoint on either `connect.squareupsandbox.com` or `connect.squareup.com`
*
* Examples:
*
* passport.use(new SquareStrategy({
* client_id: '123-456-789',
* client_secret: 'shhh-its-a-secret'
* redirect_uri: 'https://www.example.net/auth/square/callback'
* },
* function(accessToken, refreshToken, profile, done) {
* User.findOrCreate(..., function (err, user) {
* done(err, user);
* });
* }
* ));
*/
export declare class Strategy extends OAuth2Strategy {
_userProfileURL: string;
constructor(options: SquareStrategyOptions, verify: VerifyFunction);
/**
* Retrieve the merchant profile from Square, see
* https://developer.squareup.com/reference/square/merchants-api/retrieve-merchant
* for details
*
* This function constructs a normalized profile, with the following properties:
*
* - `provider` always set to `square`
* - `id` `merchant.id`, The Square-issued ID of the merchant.
* - `businessName` `merchant.business_name`, The business name of the merchant.
* - `country` `merchant.country`, The country code associated with the merchant account, in ISO 3166 format.
* - `languageCode` `merchant.language_code`, The language code associated with the merchant account, in BCP 47 format.
* - `currency` `merchant.currency`, The currency associated with the merchant account, in ISO 4217 format.
* - `mainLocationId` `merchant.main_location_id`, The ID of the main Location for this merchant.
* - `status` `merchant.status`, The merchant status, active or inactive.
*
*
* @param {String} accessToken
* @param {Function} done
* @api protected
*/
userProfile(accessToken: string, done: (err: any, user?: any) => void): void;
}