Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/socios oauth2 #250

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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