> ## Documentation Index
> Fetch the complete documentation index at: https://help.suggix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate SSO Token

> Generate JWT-based SSO tokens on your server for Suggix authentication.

### Install a JWT library

We use JSON Web Tokens to securely authenticate your users. First, install the appropriate JWT library for your server.

<Steps>
  <Step title="Get SSO Private Key">
    Go to your Suggix [**Dashboard → Settings → Developer**](https://www.suggix.com/_/settings/developer) to find your SSO private key.

    <img src="https://mintcdn.com/suggix/q9KsJTWjB5DXt5S7/images/sso_private_key.png?fit=max&auto=format&n=q9KsJTWjB5DXt5S7&q=85&s=b6555418abb31c43afa49ea76ffc2a25" alt="&#x22;private_key&#x22;" width="1404" height="370" data-path="images/sso_private_key.png" />

    <Warning>
      Store this key securely on your server and never share it publicly.
    </Warning>
  </Step>

  <Step title="Install a JWT library">
    <Tabs>
      <Tab title="Node.js">
        ```bash theme={null}
        npm install --save jsonwebtoken
        ```
      </Tab>

      <Tab title="C#">
        ```bash theme={null}
        dotnet add package System.IdentityModel.Tokens.Jwt
        ```
      </Tab>

      <Tab title="Go">
        ```bash theme={null}
        go get github.com/golang-jwt/jwt
        ```
      </Tab>

      <Tab title="Java">
        ```bash theme={null}
        # See instructions here:
        https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
        ```
      </Tab>

      <Tab title="PHP">
        ```bash theme={null}
        composer require firebase/php-jwt
        ```
      </Tab>

      <Tab title="Python">
        ```bash theme={null}
        pip install PyJWT
        ```
      </Tab>

      <Tab title="Ruby">
        ```bash theme={null}
        sudo gem install jwt
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Generate the JWT Token">
    <Tabs>
      <Tab title="Node.js">
        ```js theme={null}
          var jwt = require('jsonwebtoken');

          var PrivateKey = 'Your SSO Private Key';

          function createSSOToken(user) {
            var userData = {
              email: user.email,
              name: user.name,
              id: user.id, // optional
              photo_url: user.photo_url, // optional
            };
            return jwt.sign(userData, PrivateKey, {algorithm: 'HS256'});
          }
        ```
      </Tab>

      <Tab title="C#">
        ```c# theme={null}
        using System;
        using System.IdentityModel.Tokens.Jwt;
        using System.Security.Claims;
        using System.Text;
        using Microsoft.IdentityModel.Tokens;

        public class JwtHelper
        {
            private static string PrivateKey = "Your SSO Private Key";

            public static string CreateToken(User user)
            {
              byte[] keyBytes = Encoding.UTF8.GetBytes(PrivateKey);
              var securityKey = new SymmetricSecurityKey(keyBytes);

              var credentials = new SigningCredentials(securityKey, "HS256");
              var header = new JwtHeader(credentials);
              var payload = new JwtPayload
              {
                { "email": user.email },
                { "name": user.name },
                { "id": user.id }, // optional
                { "photo_url": user.photoURL }, // optional, but preferred
              };

              var securityToken = new JwtSecurityToken(header, payload);
              var handler = new JwtSecurityTokenHandler();

              return handler.WriteToken(securityToken);
            }
        }
        ```
      </Tab>

      <Tab title="Go">
        ```go theme={null}
        import (
          "github.com/golang-jwt/jwt"
        )

        const PrivateKey = "Your SSO Private Key"

        func createSSOToken(user map[string]interface{}) (string, error) {
          token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
            "email": user["email"],
            "name": user["name"],
            "id": user["id"], // optional
            "photo_url": user["photo_url"], // optional
          })
          return token.SignedString([]byte(PrivateKey));
        }
        ```
      </Tab>

      <Tab title="Java">
        ```java theme={null}
        import java.util.HashMap;

        import io.jsonwebtoken.Jwts;
        import io.jsonwebtoken.SignatureAlgorithm;

        public class SSOTokenCreator {
          private static final String PrivateKey = "Your SSO Private Key";

          public static String createToken(User user) throws Exception {
            HashMap<String, Object> userData = new HashMap<String, Object>();
            userData.put("email", user.email);
            userData.put("name", user.name);
            userData.put("id", user.id); // optional
            userData.put("photo_url", user.photoURL); // optional

            return Jwts.builder()
              .setClaims(userData)
              .signWith(SignatureAlgorithm.HS256, PrivateKey.getBytes("UTF-8"))
              .compact();
          }
        }
        ```
      </Tab>

      <Tab title="PHP">
        ```php theme={null}
        use \Firebase\JWT\JWT;

        const PrivateKey = 'Your SSO Private Key';

        function createSSOToken($user) {
          $userData = [
            'email' => $user['email'],
            'name' => $user['name'],
            'id' => $user['id'],
            'photo_url' => $user['photo_url'], // optional
          ];
          return JWT::encode($userData, PrivateKey, 'HS256');
        }
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        import jwt

        private_key = 'Your SSO Private Key'

        def create_sso_token(user):
          user_data = {
            'email': user.email,
            'name': user.name,
            'id': user.id, # optional
            'photo_url': user.photo_url, # optional
          }
          return jwt.encode(user_data, private_key, algorithm='HS256')
        ```
      </Tab>

      <Tab title="Ruby">
        ```ruby theme={null}
        require 'jwt'

        PrivateKey = 'Your SSO Private Key'

        def createSSOToken(user)
          userData = {
            email: user.email,
            name: user.name,
            id: user.id, #optional
            photo_url: user.photo_url, # optional
          }

          JWT.encode(userData, PrivateKey, 'HS256')
        end

        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>
