Upgrade to Pro — share decks privately, control downloads, hide ads and more …

社内でしか使わない勤怠管理システムにOAuth2を導入してみた / Kagomoku #19

megos
April 20, 2019

社内でしか使わない勤怠管理システムにOAuth2を導入してみた / Kagomoku #19

megos

April 20, 2019
Tweet

More Decks by megos

Other Decks in Technology

Transcript

  1. megos Full stuck engineer (not stack) • ͔͑͝ΜཱͯͨͻͱʢJoin Us!!ʣ •

    Twitterɿ@tmegos • ϙʔτϑΥϦΦɿmegos.netlify.com
  2. ࢖ͬͨ΋ͷ • όοΫΤϯυ • Spring Boot • Spring Security •

    Kotlin • DB • PostgreSQL • ϑϩϯτΤϯυ • Vue.js • Vuetify • axios
  3. ࢖ͬͨ΋ͷ • όοΫΤϯυ • Spring Boot • Spring Security •

    Kotlin • DB • PostgreSQL • ϑϩϯτΤϯυ • Vue.js • Vuetify • axios ࠓճ͸͜͜ͷ OAuth2ͷ෦෼͚ͩ ঺հ
  4. # ਖ਼͍͠ΞΫηε৘ใ $ curl -X POST \ -d client_id=client_id \

    -d client_secret=client_secret \ -d grant_type=password \ -d username=user \ -d password=password \ http://localhost:8080/oauth/token {"access_token":"[your_access_token]","token_type":"bearer","expires _in":43199,"scope":"read"} curlͰOAuthΛୟ͘
  5. # ΫϥΠΞϯτ৘ใͷޡΓ $ curl -X POST \ -d client_id=client_id \

    -d client_secret=client_secret2 \ -d grant_type=password \ -d username=user \ -d password=password \ http://localhost:8080/oauth/token {"error":"invalid_client","error_description":"Bad client credentials"} curlͰOAuthΛୟ͘
  6. # Ϣʔβ৘ใͷޡΓ $ curl -X POST \ -d client_id=client_id \

    -d client_secret=client_secret \ -d grant_type=password \ -d username=user \ -d password=password2 \ http://localhost:8080/oauth/token {"error":"invalid_grant","error_description":"Bad credentials"} curlͰOAuthΛୟ͘
  7. # ਖ਼͍͠ΞΫηετʔΫϯ $ curl -H "Authorization: Bearer [your_access_token]" localhost: 8080/hello

    Hello! # ΞΫηετʔΫϯͳ͠ $ curl http://localhost:8080 {"error":"unauthorized","error_description":"Full authentication is required to access this resource"} # ແޮͳΞΫηετʔΫϯ $ curl -H "Authorization: Bearer bad_access_token" localhost:8080/ hello {"error":"invalid_token","error_description":"Invalid access token: bad_access_token"} ϦιʔεΛऔಘͯ͠ΈΔ