# Social login module

This module encapsulates the function of social login, and you can quickly use social login to obtain user information through a simple API.

Initiate social login authorization request:

import {AuthenticationClient} from "authing-js-sdk"
const authenticationClient = new AuthenticationClient({
   appId: "YOUR_APP_ID",
})
await authenticationClient.social.authorize("github", {
   onSuccess: (user) => {console.log(user) },
   onError: (code, message) => {}
})

# Send authorization login request

SocialAuthenticationClient().authorize(provider, options)

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, WeChat, DingTalk, 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 get user information.

# Parameters

  • provider <string> The logo of the social login service provider. For a complete list of supported provider please see: https://docs.authing.co/social-login/guide/provider-list.html (opens new window).
  • options <object>
  • options.popup <boolean> 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. The default value is: true.
  • options.onSuccess <Function> The user agrees to the authorization event callback function, the first parameter is user information.
  • options.onError <Function> Social login failure event callback function, the first parameter code is the error code, and the second parameter message is the error message. For a detailed list of error codes, please see: For detailed description, please see: Authing Error Code List (opens new window)
  • options.position <object> is only valid when options.popup is ture. The position of the popup window is {w: 585, h: 649} by default.

# Example

// Login 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
 }
})
// 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) => {},
})