@hewmen/passport-twitch
Version:
Twitch authentication strategy using Helix for Passport. Supports the April 2020 Twitch changes!
81 lines • 3.16 kB
TypeScript
/**
* Module dependencies.
*/
import OAuth2Strategy, { InternalOAuthError, VerifyCallback } from "passport-oauth2";
declare type StrategyOptions = {
pem?: string;
callbackURL: string;
scope: string[];
} & OAuth2Strategy.StrategyOptions;
declare type InputStrategyOptions = Partial<StrategyOptions> & Pick<StrategyOptions, "clientID" | "clientSecret" | "scope" | "callbackURL">;
declare type UserProfile = {
provider: string;
id: string;
username: string;
displayName: string;
};
declare class OAuthStrategyWithPEM<T = any, U = any> extends OAuth2Strategy {
pem?: string;
constructor(options: StrategyOptions, verify: VerifyFunction<T, U>);
}
declare type VerifyFunction<T, U = any> = (accessToken: string, refreshToken: string, profile: T, verified: VerifyCallback) => void;
declare type DoneCallback = (e: InternalOAuthError | null, payload?: UserProfile) => void;
/**
* `Strategy` constructor.
*
* The Twitch authentication strategy authenticates requests by delegating to
* Twitch 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 occured, `err` should be set.
*
* Options:
* - `clientID` your Twitch application"s client id
* - `clientSecret` your Twitch application"s client secret
* - `callbackURL` URL to which Twitch will redirect the user after granting authorization
* - `pem` Signing certificate used for decoding a user's OIDC token
*
* Examples:
*
* passport.use(new TwitchStrategy({
* clientID: "123-456-789",
* clientSecret: "shhh-its-a-secret"
* callbackURL: "https://www.example.net/auth/twitch/callback"
* },
* function(accessToken, refreshToken, profile, done) {
* User.findOrCreate(..., function (err, user) {
* done(err, user)
* })
* }
* ))
*
* @param {InputStrategyOptions} options
* @param {VerifyFunction} verify
* @api public
*/
declare class Strategy<T = any, U = any, Y extends {
forceVerify: boolean;
} = any> extends OAuthStrategyWithPEM<T, U> {
private readonly __userProfileURL;
constructor(options: InputStrategyOptions, verify: VerifyFunction<T, U>);
/**
* Retrieve user profile from Twitch.
*
* This function constructs a normalized profile, with the following properties:
*
* - `provider` always set to `twitch`
* - `id`
* - `username`
* - `displayName`
*
* @param {String} accessToken
* @param {((e: InternalOAuthError | null, payload: UserProfile | undefined) => void)} done
* @api protected
*/
userProfile(accessToken: string, done: (e: InternalOAuthError | null, payload?: UserProfile) => void): void;
authorizationParams(options: Y): any;
}
export { Strategy, DoneCallback };
//# sourceMappingURL=oauth2.d.ts.map