Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function displayHomePage(req, res) {
${createButton('/start_authorization', '認可開始 / Start Authorize')}
${createButton('/revoke', 'トークンを取り消し / Revoke Tokens')}
<br /><br />
${createButton('/office', 'APIを呼び出し、保護されたリソースを取得 / Call API to fetch protected resource')}
${createButton('/v2/tenant', 'APIを呼び出し、保護されたリソースを取得 / Call API to fetch protected resource')}
`); // HTMLで各操作のボタンを含むレスポンスを送信
}
// PKCEを使用してOAuth2の認可フローを開始
Expand All @@ -56,7 +56,7 @@ async function startAuthorization(req, res) {
redirectUri: REDIRECT_URI,
codeVerifier,
state,
scope: ['mfc/admin/office.read'], // 認可のアクセス範囲
scope: ['mfc/admin/tenant.read'], // 認可のアクセス範囲
});
console.info('Redirecting to', authorizeUrl); // デバッグ用にURLをログ出力
res.redirect(authorizeUrl); // 認可URLにユーザーをリダイレクト
Expand Down Expand Up @@ -156,7 +156,7 @@ async function fetchProtectedResource(req, res) {
try {
// リソースの初回取得を試行
let response = await fetch(
'https://bizapis.moneyforward.com/admin/office',
'https://bizapis.moneyforward.com/admin/v2/tenant',
{
method: 'GET',
headers: {
Expand All @@ -178,7 +178,7 @@ async function fetchProtectedResource(req, res) {
return;
}
// リフレッシュしたトークンでリソース取得を再試行
response = await fetch('https://bizapis.moneyforward.com/admin/office', {
response = await fetch('https://bizapis.moneyforward.com/admin/v2/tenant', {
method: 'GET',
headers: {
Authorization: `Bearer ${tokenResponse.access_token}`, // リフレッシュしたアクセストークンを送信
Expand Down Expand Up @@ -206,7 +206,7 @@ app.get('/', displayHomePage); // ホームルート
app.get('/start_authorization', startAuthorization); // 認可を開始
app.get('/callback', handleAuthorizationCallback); // コールバックを処理してトークンを取得
app.get('/revoke', revokeAccessToken); // トークンを取り消す
app.get('/office', fetchProtectedResource); // 保護されたリソースにアクセス
app.get('/v2/tenant', fetchProtectedResource); // 保護されたリソースにアクセス
// サーバーを開始
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`); // サーバー開始メッセージをログ出力
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function displayHomePage(req: express.Request, res: express.Response) {
${createButton('/start_authorization', '認可開始 / Start Authorize')}
${createButton('/revoke', 'トークンを取り消し / Revoke Tokens')}
<br /><br />
${createButton('/office', 'APIを呼び出し、保護されたリソースを取得 / Call API to fetch protected resource')}
${createButton('/v2/tenant', 'APIを呼び出し、保護されたリソースを取得 / Call API to fetch protected resource')}
`); // HTMLで各操作のボタンを含むレスポンスを送信
}

Expand All @@ -69,7 +69,7 @@ async function startAuthorization(req: express.Request, res: express.Response) {
redirectUri: REDIRECT_URI,
codeVerifier,
state,
scope: ['mfc/admin/office.read'], // 認可のアクセス範囲
scope: ['mfc/admin/tenant.read'], // 認可のアクセス範囲
});

console.info('Redirecting to', authorizeUrl); // デバッグ用にURLをログ出力
Expand Down Expand Up @@ -193,7 +193,7 @@ async function fetchProtectedResource(
try {
// リソースの初回取得を試行
let response = await fetch(
'https://bizapis.moneyforward.com/admin/office',
'https://bizapis.moneyforward.com/admin/v2/tenant',
{
method: 'GET',
headers: {
Expand All @@ -218,7 +218,7 @@ async function fetchProtectedResource(
}

// リフレッシュしたトークンでリソース取得を再試行
response = await fetch('https://bizapis.moneyforward.com/admin/office', {
response = await fetch('https://bizapis.moneyforward.com/admin/v2/tenant', {
method: 'GET',
headers: {
Authorization: `Bearer ${tokenResponse.access_token}`, // リフレッシュしたアクセストークンを送信
Expand Down Expand Up @@ -249,7 +249,7 @@ app.get('/', displayHomePage); // ホームルート
app.get('/start_authorization', startAuthorization); // 認可を開始
app.get('/callback', handleAuthorizationCallback); // コールバックを処理してトークンを取得
app.get('/revoke', revokeAccessToken); // トークンを取り消す
app.get('/office', fetchProtectedResource); // 保護されたリソースにアクセス
app.get('/v2/tenant', fetchProtectedResource); // 保護されたリソースにアクセス

// サーバーを開始
app.listen(PORT, () => {
Expand Down