[Section 4] OAuth2 인증(Authentication)

현이·2023년 5월 18일
0

백엔드 부트캠프 TIL

목록 보기
33/37
post-thumbnail

내 방에서 본 노을 지는 풍경! 매일 반복되는 하늘이 질리지도 않게 매일 예뻤다!!
소셜 로그인으로 익숙한 OAuth2를 배웠다. 직접 로그인 인증 할때마다 상상했던 원리와 조금 비슷해서 신기했지만 Authentication Grant 부분은 직접 유형으로 나눠서 이론적으로 이해하려니까 좀 헷갈리고 힘들었던 것 같다.



OAuth2 개요

  • e.g. <구글 로그인>
    구글 로그인 -> 인증 성공 -> Access Token 전달 받음 -> Google API 사용 위해 Access Token 사용
    => 관리하는 Credential🔽 : 보안성🔼

OAuth2 사용 애플리케이션 유형

  1. 써드 파티 애플리케이션 제공 API 사용
  2. 추가 인증 서비스 제공(소셜 로그인 가능)



OAuth2 동작 방식

OAuth2 컴포넌트

  • Resource Owner : resource 소유자 (e.g. 구글 사용자)
  • Client : resource에 access하는 애플리케이션
  • Resource Server : Client 요청 수락 & resource owner에게 해당 resource 제공하는 서버
  • Authentication Server : Client가 Resource Server에 접근 권한 부여 서버
    -> 인증 성공하면 Client가 Access Token으로 접근 권한 부여

FLOW
1. resource owner가 OAuth2 인증 요청 (Client에 써드 파티 App 로그인 요청)
2. Client : 써드 파티 애플리케이션의 로그인 페이지로 redirect
3. resource owner 로그인 인증 성공
4. Authentication Server : Access Token Client에 전달!
(resource owner 말고❗❗❗)
5. Client(대리인 역할) : resource server에 resource 요청
6. resource server : 대리인 자격 증명 후 Client에 resource 전송

OAuth2 인증 프로토콜 용어

  • Authentication : Client가 Access Token 얻기 위한 수단
    -> resource owner 권한 표현하는 credential
    -> 4 types

  • Access Token : Client가 resource 접근 위해 사용하는 자격 증명용 토큰
    (Authentication Code & Client Secret로 토큰 받음)

  • Scope : Access Token으로 접근 가능한 resource 범위 (권한 지정 가능)




Authentication Grant 유형

1. Authentication Code Grant (권한 부여 승인 코드)

  • 가장 많이 쓰이는 기본 방식
  • refresh token 사용 가능
  • 권한 부여 승인을 위해 자체 생성 Authorizeation Code 전달
    (Client ↔️ Authentication Server)
  • 권한 부여 승인 요청시 response_type = code로 요청

2. Implicit (암묵적 승인 방식)

  • Authentication Code 없이 바로 Access Token 발급
  • 자격 증명 안전하게 저장 힘든 Client에 최적화
  • refresh token 사용 불가능
  • Client Scret로 클라이언트 인증 과정❌
  • 권한 부여 승인 요청시 response_type = token 요청

3. Resource Owner Password Credential Grant (자원 소유자 자격 증명 승인 방식)

  • 로그인시 필요한 정보로 Access Token 발급
  • Authentication Server, Resource Server, Client 다 같은 시스템일 때 사용 가능

4. Client Credentials Grant (클라이언트 자격 증명 승인 방식)

  • Client 자신이 관리하는 resource/Authentication Server에 Client용 제한된 resource 접근 권한 설정되어 있을 때
  • refresh token 사용 불가능

0개의 댓글