Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 934

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T03:29:07+00:00 2024-11-25T03:29:07+00:00

Crafting a social connector for Logto

  • 62k

Learn how to create a custom social connector for Logto in just a few steps.


Background

Social sign-in is a must for modern apps. It simplifies the user registration process, enhances user experience, and increases user engagement and conversion rate. In Logto, we use social connectors to sign in with a third-party social identify provider.

What is a “connector”?

Connector is a piece of mini-program that connects Logto with a third-party service. It is responsible for handling the sign-in flow, exchanging tokens, and fetching user information from the third-party service.

Logto offers a rich set of official connectors designed to simplify integration for various social platforms. As of today, there are already 30+ connectors in total, within which 10+ connectors are contributed by our open-source community. And we expect the numbers to grow rapidly in the future.

However, we understand that there are still many other platforms that do not have Logto's official support at the moment. Luckily, as an open-source platform, you can always create your own custom connectors with ease. So in this post, let's walk you through how you can create a custom social connector for Logto in just a few steps.

The sign-in flow

Before we start, let's understand the how the social sign-in flow works in Logto.

Image description

Now let's get started

The fastest way to get yourself started is to copy the code from an existing official connector and modify it to fit your needs. Let's take the GitHub connector as an example.

Step 1: Clone an existing connector package

In a connector source folder, you will find the following files:

  • index.ts: The main entry file of the connector.
  • constant.ts: The constants used in the connector.
  • types.ts: The TypeScript types used in the connector.
  • index.test.ts: The test cases for the connector.
  • mock.ts: The mock data used in the connector test cases.

Besides these files, you will also need to provide a README.md file to describe the connector, a logo.svg (optionally a logo-dark.svg for better dark mode user experience), and a package.json file to define the npm package information.

Step 2: Modify the main entry file (index.ts)

In the index.ts file, you will find most of the connector logic. There are typically 4 functions you need to implement:

  • getAuthorizationUri: Generate the authorization URI for the third-party social platform. For GitHub, it would be: https://github.com/login/oauth/authorize?client_id={clientId}&redirect_uri={redirectUri}&state={state}. Refer to the developer documentation of your target social platform to get the correct URI.
  • authorizationCallbackHandler: Safeguard the returned parameter values in the authorization callback URI, extract the authorization code and handle potential errors.
  • getAccessToken: Exchange the authorization code for an access token.
  • getUserInfo: Fetch user information from the third-party social platform with the access token.

Most of the other common logics have been taken care of in the Logto connector kit, which should make your work easier.

Finally, in the end of the file, you will just need to export the connector object, following the same code structure as the GitHub connector.

const createGithubConnector: CreateConnector<SocialConnector> = async ({ getConfig }) => {   return {     metadata: defaultMetadata,     type: ConnectorType.Social,     configGuard: githubConfigGuard,     getAuthorizationUri: getAuthorizationUri(getConfig),     getUserInfo: getUserInfo(getConfig),   }; }; 
Enter fullscreen mode Exit fullscreen mode

Step 3: Test the connector

Unit test
First, write some unit test cases and make sure the basic functionalities work as expected.

Local test

  • Setup Logto in your local environment: Logto provides several ways to run locally, you can either use CLI, or docker, or even build from source code. Check out the documentations for more details.
  • Link your custom connector to your Logto instance: Use the CLI to create a symbolic link of your connector to the Logto instance. More details.
cd logto npx @logto/cli connector link -p . 
Enter fullscreen mode Exit fullscreen mode

  • After linking the connector, you should see it in the <logto-root-path>/packages/core/connectors folder.
  • Restart your Logto instance, go to the Logto Admin Console, you should be able to see it in the social connectors list.
  • Configure your connector in “Sign-in experience” -> “Sign-up and sign-in” -> “Social sign-in”. And try it in our demo app with the “Live preview” feature.

Image description

Step 4 (optional): Publish the connector

You can publish your connector to NPM, and share it with the community. Or even raise a PR and contribute to Logto official GitHub repository to make it an official supported connector. Official connectors will be maintained by Logto dev team and made available to both open-source and Logto Cloud users.

Summary

Creating a custom social connector for Logto is not as hard as you might think. With the help of the Logto connector kit and good examples of code, you can easily create a connector in just a few steps.

And by contributing your connector, you can help more users to enjoy the social platform you bring in to Logto family.

Try Logto Cloud for free

identityopensourceprogrammingwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.