oauth 2 - link.koreatech.ac.krlink.koreatech.ac.kr/wp-content/uploads/2015/11/oauth2.0.pdf · •...

33
OAuth 2.0 Sep. 2015 Youn-Hee Han http://link.koreatech.ac.kr

Upload: buicong

Post on 08-Apr-2018

215 views

Category:

Documents


2 download

TRANSCRIPT

OAuth 2.0

Sep. 2015Youn-Hee Han

http://link.koreatech.ac.kr

² IETF RFCs– The OAuth 2.0 Authorization Framework, RFC 6749– The OAuth 2.0 Authorization Framework: Bearer Token Usage,

RFC 6750

²주 참고 자료– http://tutorials.jenkov.com/oauth2/index.html

²기타 자료– http://www.slideshare.net/aaronpk/an-introduction-to-OAuth-2– http://www.slideshare.net/amila_paranawithana/oauth2-api-

security-28375789– 이밖에 다음 전문가분들이 만든 자료 활용

• Daum 클라우드기술팀 이승철• KTH 기술전략팀 박민우

참고 문헌

2

²OAuth 1.0/2.0 출현 배경– 1) 비밀번호를 신뢰못하는 앱에 저장하기 싫다.

• 페이스북/트위터 아이디/패스워드로 다른서비스에 로그인 하고싶다.

– 2) 어떠한 앱이 내가 소유한 다른 자원에 접근하려고 할 때…• 신뢰못하는 앱에 원하는 권한만 주고 싶다• 원할 때는 신뢰못하는 앱으로 부터 권한을 회수하고 싶다.

OAuth

3

²OAuth 1.0/2.0 출현 배경

OAuth 2.0

4

²OAuth 2.0 Overview– 외부 애플리케이션에서 HTTP 서비스에 제한된 접근을 할 수 있

도록 인증(Authenticatation) 및 권한을 부여(Authorization)하는보안 프레임워크

– 예를 들어, • a game application can access a users data in the Facebook application • a location based application can access the user data of the Foursquare

application

OAuth 2.0

5

²OAuth 2.0 Overview– 3-legged

OAuth 2.0

6

(Resource Owner)

²OAuth 2.0 Overview– OAuth 2.0을 사용하기 위한 일반적인 선행절차

OAuth 2.0

7

(client_id, client_secret)

²OAuth 2.0 Overview– 핵심은 “Access Token”

• Third-Party Clinet (Consumer) 에게 ID와 Password 없이 보호된 자원 API를 사용할 수 있는 열쇠와 같은 정보

• 장점Ø서비스에 패스워드 전달없이 인증Ø필요한 기능만 부여 할 수 있음Ø언제나 다시 권한 취소 가능Ø패스워드 변경시에도 유효

OAuth 2.0

8

- 개인 사물함은 개봉못함- 10km까지만 주행가능함

Authorization Server에서

key를 받아 차를 수리해주

세요.

²Protected Resource– 접근허가를 필요로 하는 자원– 자원은 접근제어를 필요로하는 모든 인터넷 객체

• 개인 정보, 개인 친구 정보, Followers 정보 등• 문서파일, 음악, 오디오, 사용자 정보, API 등

– Resource Server에 위치함– 자원에 접근하기 위해서는 Authorization Server를 통해서 발급

받은 access token과 함께 접근해야 함

²Resource Owner– Resource serve에 있는 자원 소유자– 일반적으로 사람/업체

• 반드시 사람/업체가 소유자가 될 필요는 없음

OAuth 2.0 Roles

9

²Resource Server (Service Provider)– 자원(protected resource)를 제공하는 서버– Client는 access token을 이용해서 자원에 접근

²Client (Consumer)– 자원에 접근을 시도하는 애플리케이션– 대부분 Third-Pary 애플리케이션

OAuth 2.0 Roles

10

²Authorization Server– 특정 자원에 접근하기 위한 인증 및 권한을 부여하는 서버– Client에게 access token을 제공하여 그러한 권한을 부여함– 많은 경우 Resource Server와 Authorication Server는 동일한

기관에서 관리함– 자원 자체가 개인 정보인 경우

Resource Server와Authorization Server는동일한 서버에서 운영될 수 있음

OAuth 2.0 Roles

11

²Client (Consumer) 종류– Confidential Client

• Authorization Server가 발행하는 Client Password를 포함한 증명서(client_secret)를 안전하게 보관할 수 있는 ClientØ예: API를 직접 호출하는 웹 서버

OAuth Client 종류

12

²Client (Consumer) 종류– Public Client I – User Agent (Browser) App.

• Client 증명서를 안전하게 보관할 수 없는 ClientØ예: 브라우저기반 어플리케이션이나 모바일 어플리케이션

OAuth Client 종류

13

²Client (Consumer) 종류– Public Client II - Native App

• Desktop 또는 Smartphone Native 앱Ø패스워드 정보등이 디바이스 자체에 저장될 수 있음

OAuth Client 종류

14

²Abstract Protocol Overview

– A) Client가 Resource Owner에게 권한을 달라고 요청– B) Resource Owner가 Client에 권한 위임 허가– C) Client는 Authorization Server에게 자원 소유자가 허가했다고 알림– D) Authorization Server는 정말 Resource Owner가 허가한게 맞는지 확

인 후에 Access Token을 클라이언트에 발급– E/F) Client는 발급받은 Access Token과 함께 Resource Server에게 해당

자원 요청을 하여 받음

OAuth 2.0 컴포넌트 및 동작절차

많은 경우 Resource Owner로부터의 Grant 획득은 Authorization Server의 중개를 통해이루어짐

15

²Abstract Protocol Overview

OAuth 2.0 컴포넌트 및 동작절차

16

(A) Give me the key of your car

(B) It’s with key holder, I will give you a chit, show this to key holder and ask for key. You can’t open my private stuff box with this key

(C) Give me car key. Here is the chit of approve from owner

(D) Ok, This is accepted, here is the key

(E) Give me car to repair, this is the key

(F) Ok, have the car

Car owner

Key Holder

Car park

Mechanic

²HTTP Redirection– OAuth 2.0은 302 응답의 HTTP redirection 기능을 많이 활용함

²OAuth 2.0 Endpoints– 웹 서버 위의 URL로 접근됨

• 각 Endpoints들은 Java servlet, JSP 페이지, PHP 페이지들로 구현됨

– 3개의 Endpoints• Authorization Endpoint • Token Endpoint• Redirection Endpoint

OAuth 2.0 Endpoints

17

²3개의 Endpoints– Authorization Endpoint

• Client가 사용, 일반적으로 Authorization Server에 등록됨• 권한 (Authorization Grant (Code))을 얻기 위하여 사용됨

– Token Endpoint• Client가 사용, 일반적으로 Authorization Server에 등록됨• Access Token을 얻기 위하여 사용됨

– Redirection Endpoint• Authorization Server가 사용, 일반적으로 Client에 등록됨• Access Token 등을 Client에게 반환할 때 사용됨

OAuth 2.0 Endpoints

18

²Authorization Code– Authorization Server가 Client에게 발급해주는 문자열– Client는 Authorization Code를 이용해서 Access token을얻을

수 있음

²Access Token– Client가 자원(protected resources)에 접근하기 위해서 ID와

Password 대신 사용– Client의 권한과 범위(scope)를 알아낼 수 있는 일련의 문자열

²Refresh Token– 클라이언트가 같은 access token을 오래 사용하면 결국은 해킹

에 노출될 위험이 높아지기 때문에 도입된 정보– 즉, Access Token의만료기간을 가능한 짧게 하고 만료가 되면

Refresh Token으로 Access Token을 새로 갱신하는 방법 활용

OAuth 2.0 절차에서 교환되는 정보

19

²Access Token and Refresh Token

OAuth 2.0 절차에서 교환되는 정보

20

²각 정보를 획득하는 절차에 따른 4가지 타입의 방식이존재함– Authorization code

• Web-server Apps

– Implicit• Browser-Apps & Mobile Apps

– Resource owner password credential– Client credential

OAuth 2.0에서 지원하는 인증 방식

21

²Authorization Code Grant 절차– 웹 서버(서버사이드 코드)에서 호출하는 등의 시나리오인

Confidential Client가 사용하는 방식– 장기 접근에 적합함. Access Token 만료시, Refresh Token 으로 갱신

Authorization Code Grant

22

I AgreeUser Agree1

2

34

²Authorization Request– Client에 의하여 Authorization Code를 얻기 위하여 Authorization

Endpoint로 전송– 파라미터

Authorization Code Grant 메시지

23

1

https://oauth2server.com/auth?response_type=code&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=photos

²Authorization Response– Authorization 성공시 파라미터

– Authorization 실패시 파라미터

Authorization Code Grant 메시지

24

2

https://oauth2client.com/cb?code=AUTH_CODE_HERE

²Token Request– Client에 의하여 Access Token을얻기 위하여 Token Endpoint로

전송– 파라미터

Authorization Code Grant 메시지

25

3

POST https://api.oauth2server.com/token{grant_type=authorization_code&code=AUTH_CODE_HERE&redirect_uri=REDIRET_URI&client_id=CLIENT_ID&client_secret=CLIENT_SECRET}

²Token Response– Token Response는 다음과 같은 JSON 포맷으로 전달됨

• access_tokenØ the access token as assigned by the authorization server

• token_typeØ type of token assigned by the authorization serverØ Usually “bearer”

• expires_inØ a number of seconds after which the access token expires, and is no

longer validØ it is optional

• refresh_tokenØ in case the access token can expire, the refresh token is used to obtain

a new access token

Authorization Code Grant 메시지

26

4

² Implicit Grant 절차– Public Client인 브라우저 기반의 어플리케이션 (Javascript

application) 이나 모바일 어플리케이션에서 사용하는 방식– Authorization 이후 곧바로 Access Token 발급

Implicit Grant

27

OAT

1

2

² Implicit Grant Request– Client에 의하여 Implicit Grant를 얻기 위하여 Authorization

Endpoint로 전송– 파라미터

Implicit Grant 메시지

28

1

https://oauth2server.com/auth?response_type=token&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=photos

² Implicit Grant Response– Authorization 성공시 파라미터

– Authorization 실패시 파라미터

Implicit Grant 메시지

29

2

https://oauth2client.com/cb#token_type=bearer&access_token=ACCESS_TOKEN&expires_in=32342145222

²Resource owner password credential 절차– Resource owner와 Client 사이에 매우 강한 신뢰 관계가 있을 때

Resource owner password credential

30

Resource owner

Authorization Server

(A) Resource owner password credentials

(B) Resource owner password credentials

(C) Access token

Client

POST https://api.oauth2server.com/token {grant_type=password&username=USERNAME& password=PASSWOD&client_id=CLIENT_ID}

²Client credential 절차– Client가 Resource Owner 일 때, 혹은– Client가 Resource owner에 의해 강한 신뢰를 받고 있을 때– 이전에 이미 임의의 방법에 의하여 해당 Client에 대한 인증/권한이

부여가 되어 있을 때

Client credential

31

Authorization Server

(A) Client Authentication

(B) Access Token

POST https://api.oauth2server.com/token {grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET}

²Access Token을 실어서 자원 서버로 API 호출²Access Token을 싣는 방법 (Bearer Token, RFC6750)

– Authorization Request Header Field

– URI Query Parameter

– Form-Encoded Body Parameter

자원 접근

32

²OAuth 2.0의 단점– Access Token이 암호화되지 않음– 단점 극복 방안

• 위 단점을 타개하는 기술 è HTTPS (TLS)• 고유 확장은 하지 말것을 추천!!! è 표준 활용

²OAuth 2.0은 사실상의 De facto Standard – 구글과 Facebook에서는 자신들이 보유하고 있는 자원을 모두 최근

OAuth 2.0 인증으로 보호하고 있음

OAuth 2.0의 단점 및 HTTPS

33

TLS

TLS

TLS