From dd2dc14fdd52580de17c2a5009afb99c3bd1ab1d Mon Sep 17 00:00:00 2001 From: "S.Nakamatsu" <19329+snaka@users.noreply.github.com> Date: Sun, 26 Sep 2021 12:48:19 +0900 Subject: [PATCH] Update the Authorization method for the GitHub API The way to send `access_token` as a query parameter has been deprecated and changed to using the `Authorization` header. See also: https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/ --- chapter-05/photo-share-api/lib.js | 12 +++++++++--- chapter-06/photo-share-api/lib.js | 12 +++++++++--- chapter-07/photo-share-api/lib.js | 12 +++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/chapter-05/photo-share-api/lib.js b/chapter-05/photo-share-api/lib.js index ec52fc2..52dfca6 100644 --- a/chapter-05/photo-share-api/lib.js +++ b/chapter-05/photo-share-api/lib.js @@ -22,9 +22,15 @@ const requestGithubToken = credentials => ).then(res => res.json()) const requestGithubUserAccount = token => - fetch(`https://api.github.com/user?access_token=${token}`) - .then(res => res.json()) - + fetch( + 'https://api.github.com/user', + { + headers: { + Authorization: `token ${token}` + } + } + ).then(res => res.json()) + const authorizeWithGithub = async credentials => { const { access_token } = await requestGithubToken(credentials) const githubUser = await requestGithubUserAccount(access_token) diff --git a/chapter-06/photo-share-api/lib.js b/chapter-06/photo-share-api/lib.js index ec52fc2..52dfca6 100644 --- a/chapter-06/photo-share-api/lib.js +++ b/chapter-06/photo-share-api/lib.js @@ -22,9 +22,15 @@ const requestGithubToken = credentials => ).then(res => res.json()) const requestGithubUserAccount = token => - fetch(`https://api.github.com/user?access_token=${token}`) - .then(res => res.json()) - + fetch( + 'https://api.github.com/user', + { + headers: { + Authorization: `token ${token}` + } + } + ).then(res => res.json()) + const authorizeWithGithub = async credentials => { const { access_token } = await requestGithubToken(credentials) const githubUser = await requestGithubUserAccount(access_token) diff --git a/chapter-07/photo-share-api/lib.js b/chapter-07/photo-share-api/lib.js index ba8c272..cffe431 100644 --- a/chapter-07/photo-share-api/lib.js +++ b/chapter-07/photo-share-api/lib.js @@ -22,9 +22,15 @@ const requestGithubToken = credentials => ).then(res => res.json()) const requestGithubUserAccount = token => - fetch(`https://api.github.com/user?access_token=${token}`) - .then(res => res.json()) - + fetch( + 'https://api.github.com/user', + { + headers: { + Authorization: `token ${token}` + } + } + ).then(res => res.json()) + const authorizeWithGithub = async credentials => { const { access_token } = await requestGithubToken(credentials) const githubUser = await requestGithubUserAccount(access_token)