Skip to content

Commit

Permalink
Added auth tokens example (#22)
Browse files Browse the repository at this point in the history
* Added auth tokens example

* Minor fixes

* PR feedback
  • Loading branch information
corbadoman committed Jan 21, 2024
1 parent 4c00f5b commit 79321c7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/authTokens/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const express = require('express');
const Corbado = require('@corbado/node-sdk');

const app = express();

const config = new Corbado.Config(process.env.CORBADO_PROJECT_ID, process.env.CORBADO_API_SECRET);
const sdk = new Corbado.SDK(config);

app.get('/validateAuthToken', async (req, res) => {
try {
const corbadoAuthToken = req.query.corbadoAuthToken;
const request = {
token: corbadoAuthToken,
clientInfo: {
remoteAddress: '127.0.0.1',
userAgent: 'Corbado Node.js SDK Example'
}
}

// Returns response on valid auth token, throws exception on invalid auth token
const response = await sdk.authTokens().validate(request)

res.send(response.data.userID);

} catch (error) {
res.send(error);
}
});

app.listen(8080, () => {
console.log('Listening on port 8080');
});
15 changes: 15 additions & 0 deletions examples/authTokens/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "authtokens",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@corbado/node-sdk": "^2.0.0",
"express": "^4.18.2"
}
}
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/session/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "session",
"version": "1.0.0",
"description": "",
"main": "example.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@corbado/node-sdk": "^2.0.0"
},
"devDependencies": {
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}

0 comments on commit 79321c7

Please sign in to comment.