From 71ba7ff67c928b7a04fb6f6719220eeac1bfe924 Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Fri, 31 Dec 2021 15:55:38 +0800 Subject: [PATCH] post obfuscated as application/json --- pages/api/index.ts | 1 + pages/onedrive-vercel-index-oauth/step-3.tsx | 18 +++++++++++++----- utils/odAuthTokenStore.ts | 5 ++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pages/api/index.ts b/pages/api/index.ts index 5fb4226..5242392 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -24,6 +24,7 @@ const encodePath = (path: string) => { async function getAccessToken(): Promise { const { accessToken, refreshToken } = await tokenStore.getOdAuthTokens() + console.log(accessToken, refreshToken) // Return in storage access token if it is still valid if (typeof accessToken === 'string') { diff --git a/pages/onedrive-vercel-index-oauth/step-3.tsx b/pages/onedrive-vercel-index-oauth/step-3.tsx index 80f0817..ed04b4b 100644 --- a/pages/onedrive-vercel-index-oauth/step-3.tsx +++ b/pages/onedrive-vercel-index-oauth/step-3.tsx @@ -144,11 +144,19 @@ export async function getServerSideProps({ query }) { // We perform a POST request to the default API route to store the tokens inside the main route memory // This is a bit of a hack, but it's the only way to get the tokens to the main route - await axios.post('/api', { - obfuscatedAccessToken: obfuscateToken(accessToken), - accessTokenExpiry: parseInt(expiryTime), - obfuscatedRefreshToken: obfuscateToken(refreshToken), - }) + await axios.post( + '/api', + { + obfuscatedAccessToken: obfuscateToken(accessToken), + accessTokenExpiry: parseInt(expiryTime), + obfuscatedRefreshToken: obfuscateToken(refreshToken), + }, + { + headers: { + 'Content-Type': 'application/json', + }, + } + ) return { props: { diff --git a/utils/odAuthTokenStore.ts b/utils/odAuthTokenStore.ts index aaf2315..6b53912 100644 --- a/utils/odAuthTokenStore.ts +++ b/utils/odAuthTokenStore.ts @@ -1,9 +1,9 @@ // This should be only used on the server side, where the tokens are stored with KV store using // a file system based storage. The tokens are stored in the file system as JSON at /tmp path. -// import os from 'os' +import os from 'os' import Keyv from 'keyv' -// import { KeyvFile } from 'keyv-file' +import { KeyvFile } from 'keyv-file' // console.log(`${os.tmpdir()}/od-auth-token.json`) @@ -12,7 +12,6 @@ export default class TokenStore { constructor() { this.kv = new Keyv() - // this.kv = new Keyv({ // store: new KeyvFile({ // filename: `${os.tmpdir()}/od-auth-token.json`,