요약
goal(목표)
문제상황: github의 graphql 의 explorer에서 private 한 repository 에 접근할 수 없다.
Oauth token을 발급해서 header에 넣어도 접근 불가.
"Although you appear to have the correct authorization credentials,
the `***` organization has enabled OAuth App access restrictions,
meaning that data access to third-parties is limited.
For more information on these restrictions, including how to enable this app,
visit https://docs.github.com/articles/restricting-access-to-your-organization-s-data/"
문제 해결 과정
1. token이 유효한지 확인
github 공식 문서에 있는 curl 요청을 참고해서 private repo에 접근할 token이 유효한지 확인해볼 수 있다.
curl --request GET \
--url "https://api.github.com/repos/{owner 이름}/{레포 이름}" \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer {YOUR-TOKEN}"
token이 유효하다면 다음과 같이 요청에 대한 응답이 온다.
2. network 를 확인한다
restAPI + Curl 요청을 통해 token 유효성을 확인했는데도 graphql 요청이 정상적이지 않은 상황
network 탭에서 원하는 대로 요청이 가고 있는 지 확인해보니 request를 누르면 아래와 같이 직접 graphql을 찌르는 것이 아니라 /proxy에 요청을 보내는 것을 확인할 수 있다.
githubb graphql endpoint를 확인해보면 endpoint가 https://api.github.com/graphql 이다.
3. 만약에 제대로된 endpoint로 token 넣어서 요청 보내면 될까?
postman이 graphql 요청을 지원해서 postman으로 확인해볼 수 있다.
Header 정보에 Authorization Bearer + 값 넣고 graphql 요청을 보낸다
결과는 성공적으로 리턴된다.
여기서 두 가지 가정을 해볼 수 있는데
(1) /proxy request 를 허용하는데 header가 제대로 전달되지 않고 있거나
(2) /proxy request가 private repository에 열려있지 않으면 token이 유효해도 unauthorized 요청이 되거나
확인방법은 생각보다 간단했다.
postman에서 정상작동 되니까 urldp '/proxy'를 붙여서 보내보니 not found(해당 token으로 repository를 찾을 수 없음)이 리턴된다.
따라서 header정보가 정상적으로 보내져도 /proxy가 private repo에 열려있지 않으면 안되는 것 같다.
TBD
Reference
'백엔드 개발 > 백엔드 일기' 카테고리의 다른 글
#024. TS 선언문(:타입)과 단언문(as 타입) 구분해 사용하기 (0) | 2023.01.26 |
---|---|
#023. 무중단 배포: Readiness 와 Liveness 설정하기 (1) | 2022.12.30 |
#021. nginx의 reverse proxy로 cors 에러 해결하기 (0) | 2022.09.18 |
# 020. root domain으로 express cookie 세팅하기 (0) | 2022.08.29 |
#019. API 수정 (0) | 2022.06.23 |