Skip to content

Commit

Permalink
refactor: short-lived token authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
rayriffy committed Jun 20, 2024
1 parent 2d5c88d commit aaf9262
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/constants/secrets/riffyApiCredentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const riffyApiCredentials =
import.meta.env.RIFFY_CREDENTIALS ?? process.env.RIFFY_CREDENTIALS
3 changes: 0 additions & 3 deletions src/constants/secrets/riffyApiToken.ts

This file was deleted.

9 changes: 7 additions & 2 deletions src/pages/api/wallet/apple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { APIRoute } from 'astro'

import { getEvents } from '$functions/getEvents.ts'
import { riffyApiToken } from '$constants/secrets/riffyApiToken'
import { riffyApiCredentials } from '$constants/secrets/riffyApiCredentials.ts'
import { getServiceAccountIdToken } from '../../../backend/gardenGate/getServiceAccountIdToken.ts'

export const GET: APIRoute = async ({ locals, request }) => {
const eventId = new URL(request.url).searchParams.get('event')
Expand Down Expand Up @@ -41,10 +42,14 @@ export const GET: APIRoute = async ({ locals, request }) => {
}

const url = `https://api.rayriffy.com/walletPasses/garten/apple?${new URLSearchParams(payload).toString()}`
const verifyToken = await getServiceAccountIdToken(
'https://github.com/rayriffy/api',
riffyApiCredentials
)

return fetch(url, {
headers: {
Authorization: `Bearer ${riffyApiToken}`,
Authorization: `Bearer ${verifyToken}`,
},
})
}

0 comments on commit aaf9262

Please sign in to comment.