-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from TokenScript/feature/socios-oauth2
Feature/socios oauth2
- Loading branch information
Showing
25 changed files
with
22,364 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.ENV | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)); | ||
|
||
|
||
|
||
|
Oops, something went wrong.