1. 특징

    1. 사용자가 직접 비밀번호를 알려주지 않아도 제3자를 통해 로그인할 수 있게 해주는 인증/인가 프레임워크
    2. 예시
      1. 우리 서비스 = 포털 서비스
      2. 구글 / 카카오 = 인증기관
      3. Access token = 키, 비밀번호
    3. 카카오랑 같은 SNS로그인 서버를 Resource Server라고 부른다.
    4. 자원의 소유자 즉 유저는 Resource Owner라고 부른다.
    5. 우리의 서비스는 client라고 한다.
    6. SNS서비스 등록의 세가지 요소
      1. Client ID = 애플리케이션 식별자
      2. Client Secret = 식별자에 대한 비밀번호
      3. Authorized Redirect URLs 돌아올 주소
    7. 과정
      1. 버튼을 누르면 특정 서비스의 URL에 가도록 설정을 한다.
        1. 특정 URL예시

          const googleAuthUrl ='<https://accounts.google.com/o/oauth2/v2/auth?'+>
          	'client_id=YOUR_CLIENT_ID&' + //client_id
          	'redirect_uri=http://localhost:3000/auth/google/callback&' +//redirect_uri
          	'response_type=code&' +
          	'scope=profile email';
          
          
        2. 이 예시의 내용이 Resource Server의 내용과 같으면 동작하고 불 일치하면 동작을 안 한다.

        3. 과정

          1. 유저가 카카오로 로그인을 클릭
          2. 우리 서비스가 사용자를 Authorization Server로 리다이렉트
          3. Authorization Server(카카오 로그인 인증 서버) 사용자에게 화면을 표시
          4. 사용자가 카카오에 비밀번호를 입력하고 로그인
          5. 사용자를 다시 Client로 리다이렉트 + code 전달
          6. 받은 코드를 우리 서비스가 Authorization Server(카카오)에 보냄
          7. Authorization Server가 code가 유효한지 확인후 Access Token발급 Client에게 Access Token전달
          8. Access Token으로 Resource Server에 사용자 정보 요청
          9. 토큰 확인 후 사용자 정보 전달
          10. 로그인 완료 사용자에서 서비스 제공
  2. 리프레시 토큰

    1. 엑세스 토큰의 수명이 끝났을때 이 토큰을 통해여 엑세스 토큰을 재발급한다.급한다.
    2. 보안성이 뛰어남
  3. OAuth2 변수

    1. application.properties

      spring security.oauth2.client.registration.서비스이름.client-name=naver
      spring.security.oauth2.client.registration.서비스이름.client-id=발급아이디
      spring.security.oauth2.client.registration.서비스이름.client-secret=발급 비밀번호
      spring.security.oauth2.client.registration.서비스이름.redirect-uri=사이트 주소
      spring.security.oauth2.client.registration.서비스이름.authorization-grant-type=authorization_code
      spring.security.oauth2.client.registration.서비스 이름.scope=name, email ///가져올 항목
      
      #provider
      spring.security.oauth2.client.provider.서비스명.authorization-uri = 서비스 로그인 창 주소
      spring.security.oauth2.client.provider.서비스명.token-uri=토큰 발급 서버 주소
      spring.security.oauth2.client.provider.서비스명.user-info-uri=사용자 정보 획득 주소
      spring.security.oauth2.client.provider.서비스명.user-name-attribute= 응답 데이터 변수
      
    2. 이렇게 uri는 여기다가 써주고 OAuth2가 이 주소들을 로그인할때 거치기 때문에 따로 Redirect URI 빼고는 컨트롤러 거치는 과정이 필요없다.