Skip to content

Commit

Permalink
Merge pull request #250 from TokenScript/feature/socios-oauth2
Browse files Browse the repository at this point in the history
Feature/socios oauth2
  • Loading branch information
nicktaras authored Sep 11, 2023
2 parents db786db + 3b4d227 commit 83961d8
Show file tree
Hide file tree
Showing 25 changed files with 22,364 additions and 0 deletions.
2 changes: 2 additions & 0 deletions socios-oauth2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.ENV
node_modules
26 changes: 26 additions & 0 deletions socios-oauth2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# socios-oauth2

## Development

`npm run start`

## Set up

1. Add a `.env` file to the root of your project with the following keys and values. Please reference details from your
socios development account to complete this.
````
SOCIOS_CUSTOMER_KEY="..."
SOCIOS_CUSTOMER_SECRET="..."
SOCIOS_AUTH_KEY="..."
SOCIOS_REDIRECT_URI="..."
SOCIOS_PARTNER_TAG="..."
SOCIOS_RETURN_TO_APP_URL="..."
SOCIOS_COLLECTION_ID="..."
````

2. Once added, `run npm i` then `run npm start`





70 changes: 70 additions & 0 deletions socios-oauth2/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import path from "path";
import express from "express";
import { Server } from "./../token-negotiator-server/dist/index.js";
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;

// 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("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,
}
}
});

// Same origin Cors
const corsOptions = { origin: 'http://localhost.5000' }

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

app.get("/user-login-callback", 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.listen(port, () => console.info(`App listening on port ${port}`));




Loading

0 comments on commit 83961d8

Please sign in to comment.