Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9a7i committed Oct 3, 2022
1 parent 4121366 commit beea475
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = { path: '/api', handler: app }
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())


var timeout = require('connect-timeout');
app.use(timeout(1000*60*30));

Expand Down
48 changes: 47 additions & 1 deletion api/swarm.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
const express = require('express')
const router = express.Router()
const axios = require('axios').default;

const router = express.Router()

router.get('/' ,(req, res) => {
res.write('Hey from swarm!');
res.end()
})

router.post('/access_token' ,async (req, res) => {
console.log('authenticate');
try {
var response = await axios.get('https://foursquare.com/oauth2/access_token',{ params: {
client_id: req.body.client_id,
client_secret: 'DK3KXOIRRPM3CGGXUYHEDTPVJDDNPDGDE0GYHUBWRCPNQLAG',
grant_type: "authorization_code",
redirect_uri: req.body.redirect_uri,
code: req.body.code,
v: '20220901'
}})
await res.json(response.data)
}
catch (error) {
console.log(error)
res.write(JSON.stringify(error));
}
res.end()
})

router.get('/authorize' ,(req, res) => {
console.log('authorize');
//check if code exists

res.write('Hey!');
res.end()
})

router.get('/users/self' ,async (req, res) => {
try {
const auth_token = req.headers?.authorization?.split(' ')[1];
var response = await axios.get('https://api.foursquare.com/v2/users/self',{ params: {
oauth_token: auth_token,
v: '20220901'
}})
await res.json(response.data?.response?.user)
}
catch (error) {
console.log(error)
res.write(JSON.stringify(error));
}

res.end()
})

router.get('/callback' ,(req, res) => {

//check if code exists
Expand Down
1 change: 1 addition & 0 deletions components/Header.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<header class="p-5 bg-light">
<div class="container">
<a href="/">Logo</a>
This is header section
</div>
</header>
Expand Down
21 changes: 12 additions & 9 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,32 @@ export default {
pathRewrite: {'^/authenticate/': '/'}
},
'/fsapi/': {
target: 'https://api.foursquare.com/v2/',
target: 'https://localhost:3000/api/swarm/',
pathRewrite: {'^/fsapi/': '/'}
},
},


auth: {
strategies: {
foursquare : {
social : {
scheme: "oauth2",
responseType: 'code',
protocol: '',
clientId: 'OUYWUC4AHY4VSFCWA0EB055U3V4A01WYGRSAZ0MXLS0JKCUA',
clientSecret: 'DK3KXOIRRPM3CGGXUYHEDTPVJDDNPDGDE0GYHUBWRCPNQLAG',
redirectUri: 'http://localhost:3000/login',
scope: '',
state: 'vUQrsZqoqE#_=_',
codeChallengeMethod: '',
accessType: 'offline',
token: {
property: 'access_token',
type: 'Bearer',
maxAge: 1800,
},

endpoints: {
authorization: "https://foursquare.com/oauth2/authenticate",
token: "https://foursquare.com/oauth2/access_token",
userInfo: "https://api.foursquare.com/v2/users/self"
token: "http://localhost:3000/api/swarm/access_token",
userInfo: "http://localhost:3000/api/swarm/users/self"
},
grantType: "authorization_code",
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
methods: {
async loginSwarm() {
console.log('before call');
await this.$auth.loginWith('foursquare').catch(e => {
await this.$auth.loginWith('social').catch(e => {
console.log('hello')
})
},
Expand Down

0 comments on commit beea475

Please sign in to comment.