Skip to content

Commit

Permalink
Refactor the oauth flow to redirect after successful auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwi committed Jan 11, 2024
1 parent 657eed0 commit 6e6b589
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const FIREBASE_CONFIG = JSON.stringify({

const host = process.env.RELAY_HOST

async function fetchAndHandleResponse(uri, options) {
async function apiRequest(uri, options) {
const response = await fetch(uri, options);

if (!response.ok) {
Expand All @@ -43,15 +43,15 @@ async function getAccessToken(code, verifier) {
params.append('redirect_uri', process.env.OAUTH_REDIRECT_URI);
params.append('code_verifier', verifier);

return await fetchAndHandleResponse(process.env.OAUTH_TOKEN_URI, {
return await apiRequest(process.env.OAUTH_TOKEN_URI, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: params
});
}

async function getUserInfo(accessToken) {
return await fetchAndHandleResponse(process.env.OAUTH_USERINFO_URI, {
return await apiRequest(process.env.OAUTH_USERINFO_URI, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand All @@ -67,7 +67,7 @@ async function getSubscriberToken() {
application_id: process.env.OAUTH_APPLICATION_ID
}

return await fetchAndHandleResponse(`https://${process.env.SIGNALWIRE_SPACE}/api/fabric/subscribers/tokens`, {
return await apiRequest(`https://${process.env.SIGNALWIRE_SPACE}/api/fabric/subscribers/tokens`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit 6e6b589

Please sign in to comment.