[Web] oAuth

unhyif·2023년 7월 8일
1

Web

목록 보기
3/4

이전에 oAuth를 간단히 공부해 봤지만 다시 한 번 공부해 본다.

oAuth

사용자가 비밀번호를 제공하지 않고도 다른 서비스에 있는 본인 데이터에 대한 접근 권한을 위임할 수 있도록 하는 개방형 표준 프로토콜

참여 주체

  1. client: resource server의 자원을 사용하고자 하는 서비스
  2. resource server: client가 필요한 자원을 보유하고 있는 서버 (ex: Google, Facebook)
    cf) authorization server와 별개일 수도, 같을 수도 있다.
  3. resource owner: 자원의 소유자 (ex: 사용자)

절차

  1. 사전에 resource server 측에 client 서비스를 등록한다. 이때 authorization callback URL을 등록해야 한다.
  • authorization callback URL: client를 redirect 시키며 authorization code를 전달할 주소

    그리고 아래의 2가지를 부여 받게 된다.

    1) client ID: client를 구분할 수 있는 식별자
    2) client secret: client ID에 대한 비밀키


  1. resource owner가 client를 통해 resource server에 로그인을 시도한다. (ex: 소셜 로그인 버튼 클릭) 이때 client는 query string에 client ID, redirect URL, scope 등을 포함시켜야 한다.

  2. resource server는 query string을 통해 client를 검증하고, 검증이 완료되면 로그인 페이지를 띄운다.

  3. resource owner의 로그인이 완료되면, resource server는 resource owner에게 접근 권한 위임에 대한 승인을 요청한다.

  4. resource owner가 권한 위임을 승인하면 resource server는 client를 callback URL로 redirect 시키며 authorization code를 발급한다.

  5. client는 자사 backend에 authorization code를 전달한다. 그리고 backend는 resource server에 client ID, client secret, authorization code를 전달하며 access token 발급을 요청한다.

  6. resource server는 전달 받은 정보를 검사하고, 유효한 요청일 시 client에 access token을 발급해 준다. 이때 refresh token을 함께 발급하기도 한다.

  7. client는 사용자에게 로그인이 완료되었음을 알리고, 이후 access token을 이용하여 필요한 resource server의 자원을 사용할 수 있게 된다.


4가지 권한 부여 방식

oAuth는 4가지의 권한 부여 방식을 가진다.

1. Authorization Code Grant

위처럼 code를 확인한 후 access token을 발급하는 절차가 client의 backend와 resource server 간에 일어나는 방식으로, client secret과 access token이 유출될 위험을 줄일 수 있음 (response_type = code, grant_type = authorization_code)

2. Implicit Grant

Authorization Code Grant 방식의 code 관련 절차를 생략하고 바로 access token을 발급하는 방식으로, URL을 통해 access token이 유출될 위험이 있음 (response_type = token)

3. Resource Owner Password Credentials Grant

resource owner의 ID/PW만을 사용하여 access token을 요청하고 바로 발급받는 방식으로, client가 resource server가 제공하는 서비스일 때만 사용 가능함 (grant_type = password)

4. Client Credentials Grant

client의 자격 증명만을 사용하여 access token을 요청하고 바로 발급받는 방식으로, client가 resource owner일 때 사용됨 (grant_type = client_credentials)


Reference: https://tecoble.techcourse.co.kr/post/2021-07-10-understanding-oauth/
https://hudi.blog/oauth-2.0/
https://inpa.tistory.com/entry/WEB-%F0%9F%93%9A-OAuth-20-%EA%B0%9C%EB%85%90-%F0%9F%92%AF-%EC%A0%95%EB%A6%AC
https://owin2828.github.io/devlog/2020/03/11/web-4.html
https://velog.io/@wooyoung-tom/oauth
https://blog.naver.com/mds_datasecurity/222182943542

0개의 댓글