Integrate the Meta ID SDK

Let's Start

Meta ID provides SDKs for various development platforms and languages. You can choose the appropriate SDK based on your development environment and follow the installation and configuration instructions provided in the respective SDK documentation.

Here, we will use JavaScript as an example and walk you through the integration steps for Meta ID:

  1. Include the Meta ID JavaScript SDK in your application. You can achieve this by adding the following code to your HTML file:

<script src="https://metaid.io/sdk.js"></script>
  1. After the page has finished loading, initialize the Meta ID SDK and configure the necessary parameters:

<script>
  MetaID.init({
    clientId: 'YOUR_CLIENT_ID',
    redirectUri: 'YOUR_REDIRECT_URI',
    scope: 'profile address',
  });
</script>
  • clientId: The client ID obtained when you registered your application on the Meta ID platform.

  • redirectUri: The URL to which the user will be redirected after completing the login process.

  • scope: The requested scope of permissions, which can be multiple values separated by spaces.

  1. Add an event handler to your login button or link to trigger the Meta ID login flow:

<script>
  document.getElementById('login-button').addEventListener('click', function() {
    MetaID.login();
  });
</script>
  • login-button: The ID of the button in your application used for login.

  1. Once the user successfully logs in, Meta ID will redirect back to the specified redirectUri with an authorization code. You need to handle this authorization code on the redirected page and send a request to the Meta ID platform to obtain an access token:

  <script>
  var code = new URLSearchParams(window.location.search).get('code');

  if (code) {
    MetaID.getAccessToken(code)
      .then(function(response) {
        // Handle the returned access token here
        var accessToken = response.access_token;
        // ...
      })
      .catch(function(error) {
        // Handle error cases
      });
  }
  </script>

That's it! You have now successfully integrated Meta ID into your application for third-party login using the OAuth flow. Your users will be able to log in using their Meta ID accounts and enjoy the functionalities of your application.

Last updated