Issuer Configuration Socios

Socios Issuer configuration

Prerequisites:

Client-Side:

ParameterTypeDetailsOptions

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:

ParametersTypeDetailsOptions

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 discord or via sayhi@smarttokenlabs.com

Last updated