import { AuthenticationTokenProvider } from './AuthenticationTokenProvider'; import { AuthenticationClientOptions } from './types'; import { HttpClient } from '../common/HttpClient'; import { User } from '../../types/graphql.v2'; import { BaseAuthenticationClient } from './BaseAuthenticationClient'; /** * @class SocialAuthenticationClient Social Authentication Client * @description This client encapsulates the function of social authentication, and you can quickly use social login to obtain user information through a simple API. * * Initiate a social login authorization request: * * \`\`\`javascript * import { AuthenticationClient } from "approw-js-sdk" * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * await authenticationClient.social.authorize("github", { * onSuccess: (user) => { console.log(user) }, * onError: (code, message) => { } * }) * \`\`\` * * * @name SocialAuthenticationClient */ export declare class SocialAuthenticationClient { options: AuthenticationClientOptions; tokenProvider: AuthenticationTokenProvider; httpClient: HttpClient; baseClient: BaseAuthenticationClient; constructor(options: AuthenticationClientOptions, tokenProvider: AuthenticationTokenProvider, httpClient: HttpClient); /** * @name authorize * @name_zh Send authorization login request * @description Send an authorization login request. This method will directly open a new window and jump to the login authorization page of a third-party social login service provider (such as GitHub, Twitter, etc.). * After the authorization is completed, this window will be automatically closed and the onSuccess callback function will be triggered. Through this function, you can obtain user information. * * @param {string} provider The logo of the social login service provider. * @param {object} [options] * @param {boolean} [options.popup=true] Whether to open the social login window through a pop-up window, if set to false, a new browser tab will be opened in the form of window.open. * @param {Function} [options.onSuccess] The user agrees to the authorization event callback function, the first parameter is user information. * @param {Function} [options.onError] Social login failure event callback function, the first parameter code is the error code, and the second parameter message is the error prompt. For a detailed list of error codes, please see: For detailed descriptions, please see: [Approw Error Code List](https://docs.approw.co/advanced/error-code.html) * @param {object} [options.position] It is valid only when options.popup is ture. The position of the pop-up window is {w: 585, h: 649} by default. * @param {object} [options.authorizationParams] Extra parameters when requesting * * @example * * // Log in with GitHub * * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * * await authenticationClient.social.authorize("github", { * onSuccess: (user) => { console.log(user) }, * onError: (code, message) => { }, * // Customize the position of the pop-up window * position: { * w: 100, * h: 100 * } * }) * * @example * * // Use the new browser tab to open the social login page * * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * * await authenticationClient.social.authorize("github", { * popup: false, * onSuccess: (user) => { console.log(user) }, * onError: (code, message) => { }, * }) * * @memberof SocialAuthenticationClient */ authorize(provider: string, options?: { popup?: boolean; onSuccess?: (user: User) => void; onError?: (code: number, message: string) => void; position?: { w: number; h: number; }; authorization_params?: Record; authorizationParams?: Record; context?: { [x: string]: any; }; /** * @description User-defined fields that will be written to the configuration */ customData?: { [x: string]: any; }; }): Promise; }