Link copied to clipboard!
Mobile navigation button - closed state

Server Libraries

To simplify development of your Cord integration, we have server-side libraries for several languages. These make it easier to produce tokens and call our REST API


Installation

  • npm install @cord-sdk/server
    
  • $ go get cord.com/server
    
  • implementation "com.cord:server:0.0.+"
    

Generating client auth tokens

All functions generate a JWT with HS512 and an expiration time of 1 minute.

You can get your app ID and secret from the Cord console. Store your secret securely on your servers. Don’t share it with anyone, and don’t include it in client code.

See our authentication guide for a description of the behavior invoked by including optional parts of the client auth token data.

  • type PlatformUserVariables = {
        email: string;
        name?: string;
        profile_picture_url?: string;
        status?: 'active' | 'deleted';
        first_name?: string;
        last_name?: string;
    };
    type PlatformOrganizationVariables = {
        name: string;
        status?: 'active' | 'deleted';
        members?: Array<string | number>;
    };
    type ClientAuthTokenData = {
        app_id: string;
        user_id: string;
        organization_id: string;
        user_details?: PlatformUserVariables;
        organization_details?: PlatformOrganizationVariables;
    };
    
    function getClientAuthToken(app_id: string, app_secret: string, payload: Omit<ClientAuthTokenData, 'app_id'>): string;
    
  • type Status int
    
    const (
            Unspecified Status = iota
            Active
            Deleted
    )
    
    // Any values that are left at their zero value are not sent except
    // Email, which is required.
    type UserDetails struct {
            Email             string
            Name              string
            ProfilePictureURL string
            Status            Status
            FirstName         string
            LastName          string
    }
    
    // Any values that are left at their zero value are not
    // sent except Name, which is required.
    type OrganizationDetails struct {
            Name    string
            Status  Status
            Members []string
    }
    
    type ClientAuthTokenData struct {
            UserID              string
            OrganizationID      string
            UserDetails         *UserDetails
            OrganizationDetails *OrganizationDetails
    }
    
    func ClientAuthToken(appID string, secret []byte, data ClientAuthTokenData) (string, error)
    
  • /* Example usage */
    
    import com.cord.server.Cord;
    import com.cord.server.ClientAuthTokenData;
    import com.cord.server.PlatformUserVariables;
    import com.cord.server.PlatformOrganizationVariables;
    
    // "user" and "org" are your app's model objects
    String clientToken = Cord.getClientAuthToken(
        APP_ID,
        SECRET,
        new ClientAuthTokenData
              .ClientAuthTokenDataBuilder(user.getId(), org.getId())
              .organizationDetails(new PlatformOrganizationVariables
                      .PlatformOrganizationVariablesBuilder(org.getName())
                      .build())
              .userDetails(new PlatformUserVariables
                      .PlatformUserVariablesBuilder(user.getEmail())
                      .firstName(user.getFirstName())
                      .lastName(user.getLastName())
                      .profilePictureUrl(user.getProfilePictureUrl())
                      .build())
              .build());
    

Generating server auth tokens

All functions generate a JWT with HS512 and an expiration time of 1 minute.

You can get your app ID and secret from the Cord console. Store your secret securely on your servers. Don’t share it with anyone, and don’t include it in client code.

  • function getServerAuthToken(app_id: string, app_secret: string): string;
    
  • func ServerAuthToken(appID string, secret []byte) (string, error)
    
  • package com.cord.server;
    
    public class Cord {
      public static String getServerAuthToken(String appId, String secret);
    }