Zoom OAuth with a NuxtJS App, Part 1
Setup and Preliminary ServerMiddleware Work

I am a full-stack web developer that enjoys coding in Laravel and React.
Search for a command to run...
Setup and Preliminary ServerMiddleware Work

I am a full-stack web developer that enjoys coding in Laravel and React.
No comments yet. Be the first to comment.
In this series I'll discuss how I solved problems with frontend technologies like React, Vue, Next, Nuxt, Gatsby, etc. in the style of tutorials.
All About ServerMiddleware
Switching stacks

If you don't know what Twin Macro is, check it out! It's a great library that blends Tailwind CSS and Styled Component systems, like Emotion. I love using Twin because it lets me use Tailwind while separating my styling from my markup and methods. If...

Many developers know that full-stack apps with a Vue frontend can be quickly spun up with Laravel Jetstream. What many don’t know is that recently, the Laravel team made it easy to make an Inertia app with Laravel Breeze. In this article, we'll make ...

Extending the Rule Object with a DateTime Trait

Using Custom Console Commands

Some weeks ago we discussed how to do Zoom OAuth with Next.js. As was said there, we need to authenticate our calls to Zoom's API in order for us to use it, and we can either do this with JWT or OAuth. If you're building a third-party service or application, OAuth is the way to go. We'll not be using an SDK for this tutorial; everything will be done from scratch.
Preliminaries:
ngrok http 3000 wherever your Ngrok executable file is stored. NUXT_ENV_ZOOM_CLIENT_ID, NUXT_ENV_ZOOM_CLIENT_SECRET, and NUXT_ENV_BASE_URL. NB: We use the prefix NUXT_ENV_to inject it straight into the process environment, so we don't have to do anything extra in nuxt.config.js.npm run dev!The Work Begins: Here we're going to make a simple link that when clicked will help kick off the whole process.
link as a property so we can manipulate it and bind it to our a tag via v-bind:href. We need the link to be available when our page is mounted, so we'll use Vue's mounted hook.<template>
<a :href="link">Create Zoom link</a>
</template>
<script>
export default {
data(){
return {
link: '',
}
},
mounted(){
this.getZoomLink()
},
methods: {
getZoomLink(){
let url = new URL('https://zoom.us/oauth/authorize')
url.searchParams.set('response_type', 'code')
url.searchParams.set('redirect_uri', process.env.url)
url.searchParams.set('client_id', process.env.zoomclient)
this.link = url.href
},
}
}
</script>
redirect_uri that you set.The Work Continues: You should now see code in the query string in your browser's URL bar. We'll need to use this string to get our access code.
code, we'll use this.$route.query. It returns an object, so we'll first check to see if it is empty with Object.keys() to ensure we only run it when this query string is set. We'll pass it on to a property called code so that we can use its value elsewhere.created lifecycle hook instead of mounted for this part. This hook is usually used for fetching data on initialization and fires right before the mounting of our component.data(){
return {
link: '',
code: ''
}
},
created(){
const obj_length = Object.keys(this.$route.query).length
if (obj_length > 0){
this.code = this.$route.query.code
}
},
mounted(){
this.getZoomLink()
},
code string. created(){
const obj_length = Object.keys(this.$route.query).length
if (obj_length > 0){
this.code = this.$route.query.code
this.getZoomUser()
}
},
...
methods: {
async getZoomUser(){
let options = {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}
let response = await fetch(`/api/access-token?code=${this.code}`, options)
let user = await response.json()
},
}
The Work Ends: All Zoom API endpoints will need to be accessed from the server-side, hence, we'll need to use Nuxt serverMiddleware. Seriously, don't even try using the client. You'll get a lot of CORS issues. Our serverMiddleware will act as an API that will communicate with Zoom's API.
serverMiddleware: [
{path: '/api/access-token', handler: '~/api/zoom-token.js'},
]
export default function(req, res){
console.log(req)
}
Conclusion: