Skip to content

Commit

Permalink
ログアウトサーバーリクエストの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-gillingham committed Sep 19, 2023
1 parent 7d0fe01 commit eb7b6c2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
11 changes: 1 addition & 10 deletions src/state/ducks/front/login/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@ import OAuthApiUtils from "../../../../utils/OAuthApiUtils";

export function callLogin(params) {
console.log(params);
return new OAuthApiUtils().post(
"token",
{
"grant_type":"password",
"client_id": process.env.REACT_APP_API_CLIENT_KEY,
"username":params.username,
"password":params.password,
"scope":"read write"
}
)
return new OAuthApiUtils().login(params.username, params.password);
}
2 changes: 1 addition & 1 deletion src/state/ducks/shared/oauth/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function refreshToken(refresh_token: string) {
}

export function logoutAPI(access_token: string) {
// @TODO: Implement logout API
return new oAuthApiUtils().logout(access_token);
}
40 changes: 37 additions & 3 deletions src/utils/OAuthApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default class OAuthApiUtils {
* @param {string|null} baseurl カスタムURL
*/
constructor(timeout = null, baseurl = null) {
// @TODO: CHANGE TO CORRECT URL
axios.defaults.baseURL = baseurl || 'http://localhost:8080';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.timeout = timeout || process.env.REACT_APP_ECCUBE_TIMEOUT;
Expand All @@ -18,13 +17,15 @@ export default class OAuthApiUtils {
* oAuth API POST リクエスト
* @param {string} uri API アクセスポイント
* @param {Object} body Post データ
* @param headers headers
* @returns {Promise<axios.AxiosResponse<any>> | *} (API|Network) リスポンス
*/
post(uri, body) {
post(uri, body, headers = {}) {
return axios({
method: 'POST',
url: uri,
data: body
data: body,
headers: headers
});
}

Expand All @@ -33,6 +34,39 @@ export default class OAuthApiUtils {
'refresh_token': refreshToken
})
}

/**
* サーバーですべてのACCESS_TOKENを削除
*
* @param accessToken
*/
logout(accessToken: string) {
return this.post(
"/api/logout", {}, {
"Authorization": "Bearer " + accessToken,
}
)
}

/**
* ログイン
*
* @param accountEmail
* @param password
*/
login(accountEmail : string, password : string) {
return this.post(
"token",
{
"grant_type":"password",
"client_id": process.env.REACT_APP_API_CLIENT_KEY,
"username": accountEmail,
"password": password
}
)

}

}

export {axios};

0 comments on commit eb7b6c2

Please sign in to comment.