AppAuth API로 OAuth2.0 계정연동 (Android)

hyyyynjn·2021년 3월 19일
0
post-thumbnail
post-custom-banner

github 예제 로그 분석

I/AuthRepo: login called

  • AuthRepo.login()
    • AuthLoginListener 초기화 -> onStart 실행
    • AuthLoginListener는 SearchViewModel에 구현되어있음

I/SearchViewModel: Starting login

  • progressObservable,actionObservable 각각 postValue()

I/AuthRepo: Starting service config

  • AuthRepo>login()>startServiceConfig() 실행됨
    • secret.gradle 에 작성된 값(discoveryEndpoint)이 이용된다.

I/AuthRepo: Using discovery service config

  • startServiceConfig()> AuthLoginListener의 onEvent() 실행 (AUTH_SERVICE_DISCOVERY_START)
    • SearchViewModel으로 ㄱㄱ
      • 나중에 finishServiceDiscovery() 메소드도 실행시킨다.

I/SearchViewModel: Discovering service configuration

  • AuthLoginListener의 onEvent() 실행되어
    • progressObservable를 postValue() 함

I/SearchActivity: Progress change observed

  • SearchViewModel에서 progressObservable를 postValue() 히여
    • SearchActivity에서 progressObserver가 observe함
      • displayProgress() 함수 실행

I/SearchActivity: Action state change observed
Creating options menu

  • Starting login에서 progressObserver와 함께 actionObservable가 postValue()되어
    • actionObserver가 Observe함
      - invalidateOptionsMenu() 함수가 실행됨 > @Override onPrepareOptionsMenu 메소드를 실행시킴

I/SearchActivity: Preparing options menu

  • @Override onPrepareOptionsMenu 메소드 실행됨

I/SearchViewModel: Service discovery finished

  • startServiceConfig() 메소드 > finishServiceDiscovery()를 실행시킴
    • finishServiceDiscovery() 메소드에서 AuthLoginListner의 onEvent() 메소드 실행됨(AUTH_SERVICE_DISCOVERY_FINISH)
  • progressObservable.postValue()
    • 그 뒤에 finishServiceConfig() 메소드 실행됨

I/AuthRepo: Finishing service config
I/AuthRepo: authorization endpoint: https://accounts.google.com/o/oauth2/v2/auth
token endpoint: https://oauth2.googleapis.com/token
user info endpoint: https://openidconnect.googleapis.com/v1/userinfo/
Starting client config
Finishing client config
client id: 181228929225-t1j1c50a980eionj1s3umqe44eo38iah.apps.googleusercontent.com
redirect uri: com.googleusercontent.apps.181228929225-t1j1c50a980eionj1s3umqe44eo38iah:/oauth2redirect
auth scope: openid email profile https://www.googleapis.com/auth/books
Starting user auth
- finishServiceConfig() 메소드가 실행된 결과이다.
- 그 후에 startClientConfig() > finishClientConfig() > startUserAuth() 메소드 실행됨

I/SearchViewModel: Requesting user authorization

  • startUserAuth() 메소드에서 AuthLoginListener의 onUserAgentRequest() 실행됨

I/SearchViewModel: User Agent Request!

  • AuthLoginListener의 onUserAgentRequest() 실행됨
    • onUserAgentRequest() 는 activityObservable.postValue()을 실행한다.

I/SearchActivity: Progress change observed
I/SearchActivity: Activity request change observed

  • activityObserver가 Observe함
    • startActivityForResult() 에 의해 viewModel.notifyActivityResponse() 실행됨 > AuthRepo의 notifyUserAgentResponse() 실행됨

I/SearchActivity: Pausing searchBooks activity

  • 이때 Oauth2.0 Resource Server가 제공한 화면으로 넘어간다.

I/AuthRepo: Finishing user auth

  • 제대로 인증이 이뤄지면, notifyUserAgentResponse() 에서 finishUserAuth() 메소드 실행시킴

I/SearchViewModel: User authorization finished

  • finishUserAuth() 메소드 실행됨

I/AuthRepo: Starting code exchange

  • finishUserAuth() 에서 startCodeExchange() 메소드 실행됨

I/SearchViewModel: Exchanging code for access token

  • startCodeExchange() 메소드에서 AuthLoginListener의 onEvent() 메소드 실행됨(AUTH_CODE_EXCHANGE_START)
    • startCodeExchange() > onTokenRequestCompleted() 메소드 실행됨

I/SearchActivity: Resuming searchBooks activity

  • pause되어있던 SearchActivity가 resume 상태가 됨

I/SearchActivity: Progress change observed

  • AuthLoginListener의 onEvent() 메소드에 의해 Observe 실행

I/AuthRepo: Finishing code exchange

  • onTokenRequestCompleted() > finishCodeExchange() 메소드 실행됨
  • loginListener.onEvent(AuthRepo.this, AUTH_CODE_EXCHANGE_FINISH) 실행됨

I/SearchViewModel: Code exchange finished

  • loginListener.onEvent(AuthRepo.this, AUTH_CODE_EXCHANGE_FINISH) 실행
  • loginListener.onEvent(AuthRepo.this, AUTH_USER_INFO_START) 실행됨
    • 그리고 startUserInfo() 실행

I/AuthRepo: Starting user info

  • startUserInfo() 메소드가 실행되고,
    • fetchUserInfo() 메소드 실행됨.
    • onUserInfoCompleted() 실행됨

I/SearchViewModel: Gathering user information

  • AUTH_USER_INFO_START 분기처리됨

I/SearchActivity: Progress change observed
I/AuthRepo: token: ya29.a0AfH6SMB0uNWPDAid1Ux1ZLtHzV7SZ2cU2yR26IElaJ4JhrezSA6NexeibSQ0INPv_s2TseYzegLI6sJCYW3DhsP-0Byt-cm0g39FuL3tF0wb2d-4cJQbE2a4vy0zVTguyWfUXHTqJXdPO1SjwcqA14IAx8lA
I/AuthRepo: UserInfoTask response.isSuccessful() : true
I/AuthRepo: UserInfoTask doInBackground : UserInfo{lastName='하', firstName='현준', imageLink='https://lh3.googleusercontent.com/a-/AOh14Gikp1CUvhYArQvt4tNVdxNClBKIynGctoSfBKSt4R8=s96-c'}

  • fetchUserInfo() 메소드에서 UserInfoTask클래스 실행됨
    • UserInfoTask 클래스안에서 createUserInfoAPI() 실행
      • createUserInfoAPI()메소드 실행되면 -> getAccessTokenInterceptor() 실행
    • getUserInfo()에서 @GET("/oauth2/v3/userinfo") 실행되서 사용자 정보 받아옴

I/AuthRepo: Finishing user info

  • onUserInfoCompleted() 메소드 >
    • loginListener.onEvent(AuthRepo.this, AUTH_USER_INFO_FINISH)
    • finishLogin()

I/SearchViewModel: User information gathering finished
I/AuthRepo: Finishing login
I/SearchViewModel: Login succeeded
I/SearchActivity: Progress change observed
I/SearchActivity: Action state change observed
I/SearchActivity: Creating options menu
I/SearchActivity: Preparing options menu


post-custom-banner

0개의 댓글