Code Monkey home page Code Monkey logo

java_security_jwt_oauth2's Introduction

OAuth2 인증처리

개발환경

  1. spring boot
  2. spring security
  3. io.jsonwebtoken

프로젝트 프로세스

  1. id, password로 인증요청 -> 인증성공 -> access token, refresh token 발급
  2. api요청시 access token으로 요청
  3. refresh token으로 access token, refresh token 재발급
  • token은 유효성검증(token string 정확성 and expire time)

설정

  1. application.properties에 만료시간 및 secure key 설정
  • jwt.access.token.secure.key=access_key_1234
  • jwt.refresh.token.secure.key=refresh_key_1234
  • jwt.access.token.expire.time=10
  • jwt.refresh.token.expire.time=100
  1. 토큰재발급 url 설정
  • jwt.get.access.token.url=/get_access_token

실행

  1. 인증
  • url: localhost:8080/authenticate
  • body:
{  
  "username":"user",
  "password":"1234"
}
  • response body:
 {
  "jwt": {
      "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNTkwNTM3Njg5LCJpYXQiOjE1OTA1MzcwODl9.DjZeFK1eCok8Ix3YUFvU1D94y5TSGUvMvTWrDSDIGe0",
      "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNTkwNTQzMDkwLCJpYXQiOjE1OTA1MzcwOTB9.aad9zvED8vvHcUTuEZ8VSV1y6lhF3toylTUdWTEzk0U"
  }
 }    
  1. API 요청
  • URL: http://localhost:8080/hello
  • Header: ( access token 사용)
    • Authorization:Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNTkwNTM3Njg5LCJpYXQiOjE1OTA1MzcwODl9.DjZeFK1eCok8Ix3YUFvU1D94y5TSGUvMvTWrDSDIGe0
  • response body : "Hello World"
  1. 재발행요청
  • URL: http://localhost:8080/get_access_token
  • Header: ( refresh Token 사용)
  • Authorization:Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNTkwNTQzMDkwLCJpYXQiOjE1OTA1MzcwOTB9.aad9zvED8vvHcUTuEZ8VSV1y6lhF3toylTUdWTEzk0U
  • response body:
{
   "jwt": {
       "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNTkwNTQxOTgwLCJpYXQiOjE1OTA1NDEzODB9.fy4G0Hv6DA99QTQ9mOqexyqueWcrEIv6EC0zu9CQOvM",
       "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNTkwNTQ3MzgwLCJpYXQiOjE1OTA1NDEzODB9.diEpyIY3exEotFdXVLBT_ofkcrAhKmGUhH20BssZJ2s"
   }
}

java_security_jwt_oauth2's People

Contributors

seungjinhan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.