Token Negotiator
  • Introduction
  • Quick Start
    • Getting Started with NFT's
    • Getting Started with Fungible Tokens
    • Getting Started with Off Chain Tokens
  • Learn
    • Installation
    • Supported Chains
    • Supported Wallets
    • Supported Attestations
    • Event Hooks
    • Issuer Configurations
      • Issuer Configuration EVM
      • Issuer Configuration Solana
      • Issuer Configuration Flow
      • Issuer Configuration Ultra
      • Issuer Configuration Socios
      • Issuer Configuration Off Chain
    • Active Negotiation (UI)
      • Custom Views
      • View Navigation
      • Theme
      • Configuration Options
    • Passive Negotiation (no UI)
      • Wallet Connection
    • Token Authentication
      • Off Chain Authentication
      • On Chain Token Authentication (evm)
    • Smart Contract and wallet Interaction
      • Sign message
    • Off Chain Token Issuers
  • Reference
  • Articles
  • Videos
  • Showcase
  • Contribution
  • Support
  • Migrating from version 2x to 3x
  • Github Examples
Powered by GitBook
On this page
  1. Learn
  2. Issuer Configurations

Issuer Configuration Socios

Socios Issuer configuration

PreviousIssuer Configuration UltraNextIssuer Configuration Off Chain

Last updated 1 year ago

Prerequisites:

  • Socios developer account

  • Full Stack Node JS Web Application

  • Installation of (server-side)

  • Installation of Token Negotiator version 3.1.0 or greater (client-side)

Client-Side:

Parameter
Type
Details
Options

onChain

boolean

set to true

true | false

fungible

boolean

set to true (NFT support coming soon)

true | false

chain

string

set to 'eth'

string

blockchain

string

set to 'evm'

string

collectionID

string

A unique string identifier for your usage (this will be the name space your tokens are kept)

string

contract

string

set to '0x3506424F91fD33084466F402d5D97f05F8e3b4AF'

string

oAuth2options.consumerKey

string

your Socios application consumer key

string

oAuth2options.partnerTag

string

your Socios account partner tag

string

oAuth2options.endpoints.redirectURI.path

string

as per your Socios application configuration, the re-direct URI to return to after user login is complete

string

oAuth2options.endpoints.userBalance.path

string

Your back end applications endpoint utilises Token-Negotiator-Server to get user token balances

string

oAuth2options.endpoints.userNFTs.path

string

Your back end applications endpoint utilises Token-Negotiator-Server to get user NFT token balances (Not yet available)

string

oAuth2options.endpoints.userLogout.path

string

Your back end applications endpoint utilises Token-Negotiator-Server to logout the user (Not yet available)

string

Example configuration:

import { client } from "@tokenscript/token-negotiator";

const tokenNegotiator = new Client({
  type: "active",
  issuers: [
    {
      onChain: true,
      fungible: true,
      chain: "eth",
      blockchain: "evm",
      collectionID: "socios",
      contract: "0x3506424F91fD33084466F402d5D97f05F8e3b4AF",
      oAuth2options: {
        consumerKey: "YOUR_CONSUMER_KEY",
        partnerTag: "YOUR_PARTNER_TAG",
        endpoints: {
          redirectURI: {
            path: "http://localhost:5000/user-login-callback",
            params: {}
          },
          userBalance: {
            path: 'http://localhost:5000/user-balance',
            params: {}
          },
          userNfts: {
            path: 'http://localhost:5000/user-nfts',
            params: {}
          },
          userLogout: {
            path: 'http://localhost:5000/user-logout',
            params: {}
          },
        },
      },
    },
  ],
  uiOptions: {
    openingHeading:
        "Open a new world of perks with your Socios fan tokens.",
          issuerHeading: "Get discount with Socios fan tokens",
          repeatAction: "try again",
          theme: theme,
          position: "top-right",
        },
});

client.on("tokens-selected", (tokens) => {
	console.log(tokens);
})

client.negotiate();

Server-Side:

Parameters
Type
Details
Options

collectionID

string

A unique string identifier for your usage (this will be the name space your tokens are kept)

consumerKey

string

your Socios application consumer key

consumerSecret

string

your Socios application consumer secret

partnerTag

string

your Socios account partner tag

redirectURI

string

as per your Socios application configuration, the re-direct URI to return to after user login is complete

returnToApplicationURL

string

URL to re-direct the user once the application has authenticated a user via login

Example configuration:

import path from "path";
import express from "express";
import { Server } from "@tokenscript/token-negotiator-server";
import { fileURLToPath } from "url";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import cors from "cors";
import "dotenv/config";

const app = express();
const port = 5000;
const hostname = process.env.HOST;

// ES6 solution for __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

const tokenNegotiatorServer = new Server({
  issuers: {
    socios: {
      collectionID: process.env.SOCIOS_COLLECTION_ID,
      consumerKey: process.env.SOCIOS_CUSTOMER_KEY,
      consumerSecret: process.env.SOCIOS_CUSTOMER_SECRET,
      partnerTag: process.env.SOCIOS_PARTNER_TAG,
      redirectURI: process.env.SOCIOS_REDIRECT_URI,
      returnToApplicationURL: process.env.SOCIOS_RETURN_TO_APP_URL,
    },
  },
});

const corsOptions = { origin: process.env.APPLICATION_URL };

app.get("/", function (request, response) {
  response.sendFile(path.join(__dirname, "./public/index.html"));
});

app.get("/user-login-callback", cors(), async (request, response) => {
  const accessTokenData = await tokenNegotiatorServer.socios.getAccessToken(
    request.query.code,
    response
  );

  tokenNegotiatorServer.utils.setAccessTokenCookie(
    response,
    "socios",
    accessTokenData
  );

  // navigate back to the application page including the wallet provider details.
  response.redirect(`${process.env.SOCIOS_RETURN_TO_APP_URL}`);
});

app.get("/user-balance", cors(corsOptions), async (request, response) => {
  const output = await tokenNegotiatorServer.socios.getFungibleTokenBalance(
    request.cookies["tn-oauth2-access-token-socios"]
  );
  response.json(output);
});

app.get("/user-nfts", cors(corsOptions), async (request, response) => {
  const output = await tokenNegotiatorServer.socios.getNonFungibleTokens(
    request.cookies["tn-oauth2-access-token-socios"]
  );
  response.json(output);
});

app.post("/user-logout", cors(corsOptions), async (request, response) => {
  const output = await tokenNegotiatorServer.socios.userLogout(
    process.env.SOCIOS_AUTH_KEY,
    request.cookies["tn-oauth2-access-token-socios"]
  );
  response.json(output);
});

app.listen(port, hostname, () => console.info(`App listening ${hostname ?? ''} on port ${port}`));

For support and any questions please reach out to us on or via sayhi@smarttokenlabs.com

https://github.com/TokenScript/token-negotiator-server
discord