Many Changes
This commit is contained in:
54
test/oauthserver/index.js
Normal file
54
test/oauthserver/index.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const express = require('express')
|
||||
const axios = require('axios')
|
||||
const cors = require('cors')
|
||||
const querystring = require("querystring");
|
||||
|
||||
const CLIENT_ID = "3658523-0-bf5dc4c1-cce3-11ee-8a09-a1149eb4f0fe:third-party";
|
||||
const CLIENT_SECRET = "Xve6SePADrn4vgI8GwVJVnUelWTesSYR";
|
||||
const GITHUB_URL = "https://github.com/login/oauth/access_token";
|
||||
|
||||
const app = express();
|
||||
app.use(cors({ credentials: true, origin: true }));
|
||||
|
||||
app.get("/oauth/redirect", async (req, res) => {
|
||||
|
||||
console.log(req.query.code)
|
||||
|
||||
const {data,error } = await axios({
|
||||
method: "POST",
|
||||
url: `https://login.sipgate.com/auth/realms/third-party/protocol/openid-connect/token`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
data: querystring.stringify({
|
||||
client_id: CLIENT_ID,
|
||||
client_secret: CLIENT_SECRET,
|
||||
code: req.query.code,
|
||||
redirect_uri: "http://localhost:8888/oauth",
|
||||
grant_type: "authorization_code"
|
||||
})
|
||||
})
|
||||
console.log(error)
|
||||
console.log(data)
|
||||
});
|
||||
|
||||
app.get("/oauth", (req,res) => {
|
||||
res.send("Done")
|
||||
})
|
||||
|
||||
app.get("/",(req,res) => {
|
||||
let url = `https://login.sipgate.com/auth/realms/third-party/protocol/openid-connect/auth?` +querystring.stringify({
|
||||
client_id: CLIENT_ID,
|
||||
redirect_uri: "http://localhost:8888/oauth/redirect",
|
||||
scope: "account:read",
|
||||
response_type: "code"
|
||||
})
|
||||
console.log(url)
|
||||
|
||||
res.redirect(url)
|
||||
})
|
||||
|
||||
const PORT = 8888;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Listening at port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user