-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fillipe Massuda
committed
Mar 13, 2021
1 parent
2f722c3
commit 42a5d64
Showing
13 changed files
with
259 additions
and
87 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 @@ | ||
VUE_APP_CLIENT_ID= |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ node_modules | |
# local env files | ||
.env.local | ||
.env.*.local | ||
.env | ||
|
||
# Log files | ||
npm-debug.log* | ||
|
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
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
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
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
<template> | ||
<div class="wrapper"> | ||
<div v-if="accessToken"> | ||
Access Token: {{ accessToken }} | ||
</div> | ||
<div v-if="expiresAt"> | ||
Expires at: {{ expirationTime }} | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
name: 'Token', | ||
props: { | ||
accessToken: {}, | ||
expiresAt: {}, | ||
}, | ||
computed: { | ||
expirationTime() { | ||
return new Date(parseInt(this.expiresAt, 10)).toString(); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
.wrapper { | ||
padding: 20px; | ||
} | ||
</style> |
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
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
<template> | ||
<div /> | ||
</template> | ||
|
||
<script> | ||
import axios from 'axios'; | ||
export default { | ||
name: 'Callback', | ||
async created() { | ||
// receives callback to request token | ||
// code and subdomain are querystring parameters | ||
// another field is `state` that if sent in the authorize request | ||
// will be returned back useful if you need to send state data between | ||
// authorize and callback and also useful to prevent possible csrf attacks | ||
const { code, subdomain } = this.$route.query; | ||
const tokenUrl = `https://${subdomain}.thinkific.com/oauth2/token`; | ||
const tokenResponse = await axios.post(tokenUrl, { | ||
grant_type: 'authorization_code', | ||
code_verifier: localStorage.getItem('codeVerifier'), | ||
code, | ||
}, { | ||
auth: { | ||
username: process.env.VUE_APP_CLIENT_ID, | ||
}, | ||
}); | ||
// Token response attributes: | ||
// { | ||
// access_token: <access_token>, | ||
// expires_in: <seconds to expire>, | ||
// gid: <global identifier for site>, | ||
// token_type: "bearer" | ||
// } | ||
// store token | ||
localStorage.setItem('accessToken', tokenResponse.data.access_token); | ||
// store token expiration time | ||
const expiresAt = this.calculateExpirationTime(tokenResponse.data.expires_in); | ||
localStorage.setItem('expiresAt', expiresAt); | ||
// redirect to home | ||
this.$router.push('/'); | ||
}, | ||
methods: { | ||
// Stores token expiration time | ||
calculateExpirationTime(expiresIn) { | ||
const now = new Date().getTime(); | ||
// sum secods to token generated time | ||
return now + (expiresIn * 1000); | ||
}, | ||
}, | ||
}; | ||
</script> |
Oops, something went wrong.