Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jwt interceptor #33

Closed
2 tasks done
jeonghomoon opened this issue Sep 26, 2022 · 0 comments · Fixed by #34
Closed
2 tasks done

jwt interceptor #33

jeonghomoon opened this issue Sep 26, 2022 · 0 comments · Fixed by #34
Assignees
Labels
feat 기능 추가

Comments

@jeonghomoon
Copy link
Owner

jeonghomoon commented Sep 26, 2022

Description

개요

  • API 통신 시 자격 증명을 위해 Authorization header를 추가할 수 있습니다.
  • JWT 기반 인증의 경우 401 에러시 refreshToken을 이용해 토큰을 리프레시 하는 과정을 거칠 수 있습니다.
  • 해당 기능들을 Alamofire에서 지원하는 RequsetInterceptor 프로토콜을 사용하여 간단하게 구현할 수 있습니다.

요구사항

  1. Keychain 저장소에서 jwt 토큰을 가지고 Authorization header에 값을 넣을 RequestAdapter를 구현해야 합니다.
  2. RefreshToken 요청이 구현된 Routable 라우터를 가지고 경우에 따라 Refresh 요청을 수행할 RequestRetrier를 구현해야 합니다.

TODO

  • JWT Authorization header Adapter
  • JWT Refresh Token Retrier

Environment

macOS: Monterey 12.5.1, Apple M1
iOS: 15.5, iPhone 13 mini
IDE: Xcode 13.4.1

Related: #11 #29

@jeonghomoon jeonghomoon added the feat 기능 추가 label Sep 26, 2022
@jeonghomoon jeonghomoon self-assigned this Sep 26, 2022
@jeonghomoon jeonghomoon changed the title interceptor network service jwt interceptor Sep 28, 2022
jeonghomoon added a commit that referenced this issue Sep 28, 2022
JWTAuthorizable
JWTInterceptor에서 사용할 Token에 대한 인터페이스를 정의합니다.
POP 방식을 이용하여 임의의 구조체에 해당 프로토콜을 채택하여 확장할 수 있도록 하였습합니다.

JWTInterceptor
토큰 갱신을 위한 router, adapt와 retry를 위한 network/persistent service를 의존성으로 갖습니다.
요청시 Keychain에서 bearerToken을 read하여 요청의 header에 추가합니다.
unautorized error의 경우 의존성으로 받은 refreshRouter를 통해 토큰을 갱신합니다.

Refs: #33
jeonghomoon added a commit that referenced this issue Sep 28, 2022
JWTAuthorizable
JWTInterceptor에서 사용할 Token에 대한 인터페이스를 정의합니다.
POP 방식을 이용하여 임의의 구조체에 해당 프로토콜을 채택하여 확장할 수 있도록 하였습합니다.

JWTInterceptor
토큰 갱신을 위한 router, adapt와 retry를 위한 network/persistent service를 의존성으로 갖습니다.
요청시 Keychain에서 bearerToken을 read하여 요청의 header에 추가합니다.
unautorized error의 경우 의존성으로 받은 refreshRouter를 통해 토큰을 갱신합니다.

Refs: #33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 기능 추가
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant