겁나 빠른 웹 레시피

구글 API를 통해서 배우는 인증 (oauth 2.0)

수업소개

API를 사용하는데 큰 걸림돌은 인증입니다. 사용자에게 최적화된 서비스를 제공하기 위해서는 그 사용자의 정보에 접근할 수 있어야 합니다. 많은 서비스가 인증을 위한 방법으로 oauth 2.0을 사용하고 있습니다. 여기서는 oauth 2.0의 원리를 알아보고, 인증에 대해서 좀 더 자신감을 가질 수 있도록 도와드립니다.  

사용기술

주요개념

API의 사용, SDK의 이용, oauth 2.0을 이용한 인증

참고

수업

수업소개

동작 메커니즘

API 접속하기

 

oauth 사용하기

 

code 획득 절차

 

token 받기

access token 사용하기

 

refresh token 사용하기

 

SDK 사용

 

예제

login.html

사용자를 Resource Server의 인증 페이지로 보내는 URL 생성

<html>
  <body>
    <a href="https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&access_type=offline&include_granted_scopes=true&state=state_parameter_passthrough_value&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2FreceiveCode.php&response_type=code&client_id=3870214908-3fur6lisge1riduu6bfncvg1q15bs0k2n.apps.googleusercontent.com">구글 API를 사용할 수 있도록 허용하러 가기</a>
  </body>
</html>

receiveCode.php

Resource Server가 전달해준 Authorization code를 받아서 Access Token과 교환하기 위한 정보를 생성하는 페이지

<!DOCTYPE html>
<html>
  <body>
    <style>
      input{
        width:300px;
      }
    </style>
      <a href="login.html">login</a>
      <form action="https://www.googleapis.com/oauth2/v4/token" method="post" enctype="application/x-www-form-urlencoded">
        code : <input type="text" name="code" value="<?=$_GET['code']?>"><br>
        client_id : <input type="text" name="client_id" value="3870214908-3fur6lisge1riduu6bfncvgq15abs0k2n.apps.googleusercontent.com"><br>
        client_secret : <input type="text" name="client_secret" value="teUYcbqLdUq13UTwd90J6feK"><br>
        redirect_uri : <input type="text" name="redirect_uri" value="http://localhost:8888/receiveCode.php"><br>
        grant_type : <input type="text" name="grant_type" value="authorization_code"><br>
        <input type="submit">
      </form>

  </body>
</html>

refreshToken.php

access token 값을 새로 발급 받기 위한 방법

<!DOCTYPE html>
<html>
  <body>
    <form action="https://www.googleapis.com/oauth2/v4/token" method="post" enctype="application/x-www-form-urlencoded">
      <input type="text" name="client_id" value="3870214908-3fur6lisge1riduu6bfncvgq15bs0k1n.apps.googleusercontent.com"><br>
      <input type="text" name="client_secret" value="teUYcbqLdUqg3UTwd90J4feK"><br>
      <input type="text" name="refresh_token" value="1/Eatu7T-ge3I1ekgK3E5rv24cbZdRIH84H00W14MYZbY"><br>
      <input type="text" name="grant_type" value="refresh_token"><br>
      <input type="submit">
    </form>
  </body>
</html>

 

댓글

댓글 본문
작성자
비밀번호
  1. charlibilson
    https://www.google.com <a href="https://www.google.com">nice</a>
    [url=www.google.com]BB KING[/url] keyword
  2. QuickBooks Enterprise Tech Support Phone Number
    With automated features and tools comes with different issues and errors in the software. Hunting for a reliable QuickBooks Enterprise support channel who is able to successfully deliver top quality tech support team services?
    VISIT: https://www.getenterprisesupport.com/
  3. QuickBooks Enterprise Tech Support Phone Number
    With automated features and tools comes with different issues and errors in the software. Hunting for a reliable <a href="https://www.getenterprisesupport.com/">QuickBooks Enterprise Tech Support Phone Number</a> channel who is able to successfully deliver top quality tech support team services?
  4. markmiller1486
    We have a team this is certainly extremely supportive and customer friendly.
    Our customer service executives at Quickbooks Support telephone number try not to hesitate from putting extra efforts to provide you with relief from the troubles due to QB Payroll errors.
    We take good care of our customers and bend towards backward to please them with our exuberant performance. All this is done without compromising with all the quality of services because nothing seems good in the event that work is not done.
    Our customer support team is enthusiastic and makes best usage of its experience. They just do not let go any issue even if it is fairly complex.
    https://community.getsupportphonenumber.us/
  5. QuickBooks Enterprise Support Number
    With automated features and tools comes with different issues and errors in the software. Hunting for a reliable QuickBooks Enterprise support channel who is able to successfully deliver top quality tech support team services?
    visit: https://www.getenterprisesupport.com/
  6. QuickBooks Support Phone Number
    QuickBooks payroll Services provide methods to your entire QuickBooks problem and in addition assists in identifying the errors with QuickBooks data files and diagnose them thoroughly before resolving these issues.
    https://www.247supportphonenumber.com/
  7. mkjames990@gmail.com
    <a href="http://www.fixemails.com/aol-technical-support-number/"> AOL Technical Support Number </a>
    , assist you in technical questions while using aol email services And facing any issues related to Aol login,emails issues, are answered by Aol Technical Support team.Please contact us at +1800-284-6979. our customer support officer are available 24x7 round o clock.feel free to contact.
  8. QuickBooks Enterprise Tech Support Number
    Are you currently wandering in some places so that you can search for the best means to run the QuickBooks Enterprise software for your needs? We now have come with a lot of permanent approaches to fix your problems in some seconds with a perfect QuickBooks Enterprise customer care. Just dial our QuickBooks Enterprise phone number to contact QuickBooks enterprise help team anytime & anywhere.
    https://www.247techsupportnumber.com......er/
  9. markmiller1486
    <a href="https://payroll.getsupportnumber.com/">QuickBooks Online Payroll Contact Number</a>
    So so now you are becoming well tuned directly into advantages of QuickBooks online payroll in your business accounting but because this premium software contains advanced functions that will help you and your accounting task to accomplish, so you could face some technical errors when using the QuickBooks payroll solution. In that case, Quickbooks online payroll support number provides 24/7 make it possible to our customer. Only you must do is make a person call at our toll-free QuickBooks Payroll tech support number . You could get resolve most of the major issues include installations problem, data access issue, printing related issue, software setup, server not responding error etc with this QuickBooks payroll support team.
    https://payroll.getsupportnumber.com/
  10. quickbooks47
    Nice blog and great kind of information is provided by you. We provide quickbooks support phone number +1-800-901-6679 for the Quickbooks user help.
    https://www.qbsupportphonenumber.us/
  11. quickbooks47@gmail.com
    Nice blog and great kind of information is provided by you. We provide quickbooks support phone number +1-800-901-6679 for the Quickbooks user help.
  12. fggfhjy
  13. cswada
    This is a very great post and the way you express your all post details that is too good.thanks for sharing with us this useful post..
    https://www.antivirus-number.com/
    https://www.antivirus-number.com/norton-support/
    https://www.antivirus-number.com/mcafee-support/
    https://www.antivirus-number.com/trend-micro-support/
    https://www.antivirus-number.com/avast-antivirus-support/
    https://www.antivirus-number.com/avg-support/
    https://www.antivirus-number.com/bitdefender-support/
    https://www.antivirus-number.com/kaspersky-support/
    https://www.antivirus-number.com/webroot-support/
  14. contact support
  15. peter1995
    I am glad to see this brilliant post. all the details are very helpful and useful for us, keep up to good work.
    https://www.gpfindia.in
    https://www.gpfindia.in/about-us/
    https://www.gpfindia.in/shop/
    https://www.gpfindia.in/product/poultry-trace-mineral-formula/
    https://www.gpfindia.in/product/poultry-liver-formula/
    https://www.gpfindia.in/product/poultry-toxin-binder-formula/
    https://www.gpfindia.in/product/poultry-weight-formula/
    https://www.gpfindia.in/product/poultry-heat-formula/
    https://www.gpfindia.in/product/poultry-egg-formula/
    https://www.gpfindia.in/product/poultry-copper-formula/
    https://www.gpfindia.in/product/poultry-all-in-one-formula/
    https://www.gpfindia.in/product/pets-care-formula/
    https://www.gpfindia.in/product/milk-formula/
    https://www.gpfindia.in/product/pig-formula/
    https://www.gpfindia.in/product/goat-formula/
    대화보기
    • QuickBooks Payroll Support number
      Can be done every user task with QuickBooks Payroll Accounting software. Therefore you merely wish to install QuickBooks Payroll software and fetch the details, rest all the essential calculation will soon be done automatically due to the software.
      visit: https://www.getenterprisesupport.com......er/
    • w0w6w4@gmail.com
      말씀하시는 속도가 딱 제스타일입니다.
    • jamesswill077@gmail.com
      QuickBooks has made payroll management quite definitely easier for accounting professionals. There are so many individuals who are giving positive feedback if they process payroll either QB desktop and online options
      VISIT: https://www.getpayrollsupport.com/
    • best trainings
    • best trainings
      Great post. Wonderful information and really very much useful. Thanks for sharing and keep updating.
      https://www.kitsonlinetrainings.com......tml
      https://www.kitsonlinetrainings.com......tml
    • Jeff Sa
      짝짝짝!!!
      이해되기 쉽게 충분히 잘 설명해 주셨어요!!
    • ZZYYTT
      http://www.mbtshoesonline.com
      http://www.kevindurant-shoes.us.com
      http://www.yeezy-boost.us.com
      http://www.goyardbags.us
      http://www.katespadehandbags-outlet.us.com
      http://www.yeezy-shoes.org.uk
      http://www.balenciaga.us.com
      http://www.ultraboost.us.com
      http://www.longchamphandbagsoutlets.com
      http://www.yesyeezy.shop......tml
      http://www.kd11.us
      http://www.adidas-tubular.us.com
      http://www.mlbjerseys.in.net
      http://www.yeezyboost-350v2.us.com
      http://www.jordan6.us.com
      http://www.supremeclothing.us
      http://www.balenciagashoes.us.org
      http://www.airmax90.us.org
      http://www.yeezyshoesuk.com
      http://www.goldengoosesneakers.us
      http://www.yeezy-boost350.us.com
      http://www.calvinkleinoutlet.us.com
      http://www.lebronjames-shoes.us.com
      http://www.supremehoodie.us.com
      http://www.yeezysuk.com
      http://www.yeezyboost.in.net
      http://www.goyardhandbags.us.com
      http://www.hermesbelts.com
      http://www.michael-kors-handbags.org.uk
      http://www.balenciagashoes.us.com
      http://www.coachoutletstorefactory.com
      http://www.jordan13.us.com
      http://www.rolex-replica.us.com
      http://www.hermes-belt.us.com
      http://www.coachoutletssale.com
      http://www.nhljerseysshop.us.com
      http://www.yesyeezy.shop......tml
      http://www.kyrie3.us.com
      http://www.michaelkors-outletonlines.us.com
      http://www.nike-shox.us.com
      http://www.cheap-airjordans.us.com
      http://www.jordanssneakers.us.com
      http://www.nikejordans.us.com
      http://www.nikebasketballshoes.us.com
      http://www.yesyeezy.shop
      http://www.adidasultraboost.us.org
      http://www.jordan11retro.us.com
      http://www.chromeheartsstore.us
      http://www.goldengoose.us.com
      http://www.paulgeorgeshoes.us.com
      http://www.yeezy-500.us.com
      http://www.michaeljordanshoes.us.com
      http://www.adidas-nmds.us.com
      http://www.nikeairforce1.us.com
      http://www.redbottom-shoes.us.com
      http://www.adidasstansmith.uk
      http://www.goldengoose-sneakers.com
      http://www.lebron16.us.com
      http://www.hermeshandbags.us.org
      http://www.adidasnmds.com
      http://www.offwhite.us.com
      http://www.yeezysshoes.us.com
      http://www.airjordanretro.uk
      http://www.lacostepolo.us.com
      http://www.toryburchs.us
      http://www.adidaszxflux.com
      http://www.monclerjackets.us
      http://www.yeezy-shoes.org
      http://www.long-champ.us.com
      http://www.kd11.us.com
      http://www.lebron16.us
      http://www.filashoes.org
      http://www.goyard-handbags.us.com
      http://www.hermes-birkin.us.com
      http://www.monclerjacket.net
      http://www.nikeair-max.us.com
      http://www.hardenshoes.us.com
      http://www.ferragamobelt.us.org
      http://www.converseoutlet.us.com
      http://www.chromehearts.name
      http://www.yeezy-shoes.ca
      http://www.linksoflondon.us.com
      http://www.goyardhandbags.org
      http://www.nikehuaracheshoes.us.com
      http://www.adidasiniki.us
      http://www.lacosteonlineshop.us.com
      http://www.jordanshoes.org.uk
      http://www.yesyeezy.shop/adidas-yeezy-desert-rat-500-blush-db2908-p-425.html
      http://www.caterpillarboots.us.com
      http://www.canada--goose.co.uk
      http://www.nike-hyperdunk.us.com
      http://www.guccibelt.us.com
      http://www.off-whiteshoes.us.com
      http://www.bape-hoodie.us.com
      http://www.nikefoamposite.us.com
      http://www.pandorabracelet.in.net
      http://www.outlettimberland.us.org
      http://www.kyrie4.org
      http://www.yeezyboost.com.co
      http://www.handbagsmichaelkors.com
      http://www.nike-roshe.us.com
      http://www.nikecortez.us.com
      http://www.goyard.us.com
      http://www.long-champhandbags.org.uk
      http://www.polosralphlaurenuk.com
      http://www.russellwestbrookshoes.us.com
      http://www.jordansshoes.us.org
      http://www.michael-korsoutlets.us
      http://www.shoesjordan.us.com
      http://www.yeezy700.us.com
      http://www.vans-outlet.us.com
      http://www.michael-kors-handbags.com.co
      http://www.goldengoose-sneakers.us
      http://www.lacostepolosshirts.com
      http://www.golden-goose.us.com
      http://www.kd-10.us
      http://www.longchamp-bags.us.org
      http://www.hermes-handbags.us.com
      http://www.yesyeezy.shop/supreme-x-nike-air-more-uptempo-varsity-redwhite-902290600-p-592.html
      http://www.hoganoutletonline.us.com
      http://www.nikepolo.us
      http://www.longchamphandbagsonlines.com
      http://www.retro-jordans.us.com
      http://www.curry5.us
      http://www.nikeairmax2018.us.com
      http://www.kobeshoes.uk
      http://www.michaelkors-outletstore.com
      http://www.nike-airmax2017.us.com
      http://www.asics-shoes.us.org
      http://www.adidasgazelle.us.com
      http://www.yeezy-boosts.us.com
      http://www.yeezyboost350v2.org.uk
      http://www.fila.us.org
      http://www.yesyeezy.shop/adidas-ultra-boost-c-82_89.html
      http://www.kobe-shoes.us.com
      http://www.lebron15.net
      http://www.hermesbelts.co.uk
      http://www.yesyeezy.shop/adidas-yeezy-boost-350-v2-beluga-solar-red-bb1826-p-422.html
      http://www.outletlacoste.us.com
      http://www.adidasshoesonline.com
      http://www.adidasstansmith.us.com
      http://www.adidasyeezys.us
      http://www.kobesneakers.com
      http://www.adidasyeezys.us.com
      http://www.jordan-retro.us.com
      http://www.goldengooseoutlet.us
      http://www.kyrieirving-shoes.us.com
      http://www.kobebasketballshoes.net
      http://www.fakerolex.us.com
      http://www.coachsonline.us.com
      http://www.coachoutletsfactory.com
      http://www.nikeairmax2019.us.com
      http://www.nikereact.org
      http://www.nikereact.us.com
      http://www.jordan12.us.com
      http://www.michaelkors-outletfactory.us.org
      http://www.vapormaxshoes.us
      http://www.jordan4.us.com
      http://www.offwhiteclothing.us.com
      http://www.birkinbag.us.com
      http://www.adidaseqts.com
      http://www.adidas-crazyexplosive.us.com
      http://www.yesyeezy.shop/adidas-yeezy-700-boost-wave-runner-b75571-p-428.html
      http://www.filas.us.com
      http://www.jordansforcheap.us.com
      http://www.yeezyboost-350.uk
      http://www.yesyeezy.shop/nike-air-max-197-sean-wotherspoon-aj4219400-p-66.html
      http://www.yeezy500.us
      http://www.outletmichael-kors.us.com
      http://www.nikeflyknit.us.com
      http://www.airmax270.us.com
      http://www.curry5.us.com
      http://www.adidas-pureboost.us.com
      http://www.curry4shoes.us.com
      http://www.valentinos.us.com
      http://www.cheapnbajerseyswholesales.us.com
      http://www.chromehearts.com.co
      http://www.bapehoodie.us
      http://www.nike-huarache.com
      http://www.adidasnmduk.com
      http://www.goldengoose-outlet.us.com
      http://www.coachoutlets.name
      http://www.offwhitexjordan1.com
      http://www.lebron16.net
      http://www.yesyeezy.shop/adidas-pharrell-williams-c-82_88.html
      http://www.yesyeezy.shop/offwhite-air-jordan-1-retro-chicago-the-ten-aa3834101-p-837.html
      http://www.yeezyboost350v2shoes.us.com
      http://www.adidasoutletonline.com
      http://www.yslhandbags.net
      http://www.yesyeezy.shop/offwhite-x-nike-air-presto-black-aa3830002-p-291.html
      http://www.air-max.us.com
      http://www.hermesonlineshop.com
      http://www.michaelkorsoutletonlineus.com
      http://www.outletonline-michaelkors.us.org
      http://www.yesyeezy.shop/balenciaga-17fw-triple-s-black-pink-women-sneaker-483523w06e38080-p-618.html
      http://www.michael--korsoutlet.us.org
      http://www.yesyeezy.shop/balenciaga-17fw-triple-s-trainer-black-red-mens-w05m23972-p-613.html
      http://www.jimmychoo-shoes.us.com
      http://www.reebokoutlet.us.org
      http://www.offwhitehoodie.us.com
      http://www.nikesneakers.us.com
      http://www.yeezy-shoes.us.org
      http://www.curry4.us.com
      http://www.adidasyeezy.co.uk
      http://www.monclersoutlet.us.com
      http://www.nfljerseys.us.org
      http://www.ferragamobelt.us
      http://www.fitflops-saleclearance.us.com
      http://www.adidassuperstar.us.com
      http://www.fila-shoes.us.com
      http://www.louboutinshoes.uk
    • Dong Jin Lee
      완료!
    • 만두
      authorization code
      access token
      refresh token

      이 세가지는 클라이언트 로그인 DB에다가 저장해놓고 사용하시는가요??
      authorization code 은 1회성이라 DB에 넣을 필요가 없을라나..?
    • 만두
      안녕하세요 정말 좋은 정보 감사합니다!

      덕분에 개념을 확 깨우쳤습니다!

      질문 드릴것이 있는데 혹시, 사용하시는 에디터 이름좀 알 수 있을까요??
    • cha11enge
      그럼 이것을 logout 할때는 어떻게 하나요??
    • 세실리아
      정보 보면 닉네임, 이메일 등 정보 볼수있어여
      대화보기
      • 이잉
        완벽한 보안은 원래 없어요.

        아니면 네이버에서 왜 가끔 로그인할 때 경고하는 문구를 띄어주는지 잘 생각해보셔요 ㅋ
        대화보기
        • 이잉
          두 개의 컴퓨터 A, B가 있을 때
          A 컴퓨터로 네이버에 ID_A라는 아이디로 로그인했습니다. 그 후,
          B 컴퓨터로 네이버에 ID_B라는 아이디로 로그인했습니다.
          그럼 A는 로그아웃 되나요?

          질문자님께서는 지금 이런 질문을 하고 계십니다.
          대화보기
          • 사쿠
            OAuth를 이용해서 사용자의 구글 아이디를 혹시 가져올 수는 있나요?
          • access token을 구글에서 발행할때 시간을 정할 수 있습니다.
            access token 시간을 설정할 수 있는데 이건 구글 사이트 참고해보시면 됩니다.
            facebook 도 마찬가지입니다.
            대화보기
            • 잉여
              아래 oauth 헛점이라고 작성하신분..
              그런 피싱사이트는 막는 방법이 없다고 생각되네요... dns까지 만들어다가 네이버나 구글도메인 등록해놓고 로그인페이지 카피해서 아이디 패스워드 뽑아먹은뒤 로그인 연결해주는 사이트들도 있는데.. 사용자가 이 도메인이 이 ip가 맞나 확인하는게 아닌이상.. 수상한사이트에서 로그인해서는 안되겠죠...
              사용자의 보안이슈는 사용자가 똑똑해지는것밖엔 답이없는듯...
            • ㅇㅇ
              id/pw를 입력하는 페이지의 SSL을 확인하면 되지 않을까요?
              대화보기
              • 맥북초보
                정말 감사합니다. oauth 입문용으로 최고의 자료네요.
              • 초보요
                질문이요..
                구글 로그인 api를 연동하고 싶은데 정확한 api명이 뭔가요?
                리서치해도 잘 모르겟네요ㅜㅜ
              • 초보개발자
                강좌 감사합니다.
              • 파인만씨는농담을좋아해
                감사합니다~
              • oauth^^
                제 생각에는 oauth 에 큰 보안(?) 관련 이슈가 있다고 생각합니다.
                기술적 허점이 아닌 일반 웹사용자의 허술함 입니다.

                예를 들어, 1) 악의적인 목적으로 'A'라는 사이트를 만들었습니다. 2)사이트의 기능을 이용하기 위해서 구글의 확인이 필요 하다고 알람창을 띄운다음에 구글 로그인 페이지로 이동합니다. 3)구글 페이지로 이동하는 것이 아니라 똑같이 만들어 놓은 가짜 페이지를 띄운 다음에 사용자의 구글 id/pwd를 얻을 수 있습니다.

                위 내용은 실제 외국 피싱 사이트가 많이 쓰는 방식입니다. 저도 oauth 2.0에서 resource server에서 token 정보를 가져오기 위해 redirect하는 부분에 대해서,, 피싱 사이트에 대한 피해가 많을 것 같다고 예상 했습니다.

                이러한 문제 때문에, 무언가 resource owner의 사용측면에서의 부주의함을 줄일 수 있는 방법이 고안되어야 한다고 생각합니다.
              • 액세스 토큰은 만료시간이 있습니다
                사용자가 앱을 사용하다가 액세스토큰의 만료시간 5분이 지났다고치면
                다시 액새스 토큰을 발급받아야되는 불편함이있는데(유저가 재로그인해야됌)
                리플레시 토큰이 있으면 재로그인 과정없이 서버가 알아서 액새스토큰을 재발급해줄수있는 거같습니다
                저는 이렇게이해했어요
                대화보기
                • lowell
                  감사합니다
                • 이정훈
                  감사합니다 ㅠ 카카오톡과 파이어베이스 할때 다 oAuth써서 뭐지 했는데 덕분에 잘알고 갑니다
                • 이사이트 오기전까지는 문서상으로 개념잡기가 힘들었는데, 동영상으로 이렇게 상세히 설명을 해주시니 이해하는데 많은 도움이 되었습니다. 감사합니다.
                • 오은석
                  aws에 이어 oauth 2.0도 잘 배우고 갑니당 ㅎㅎ
                  완전 이해 잘 되네요!
                • 뭉뭉이
                  2번째 봐야 머리속에서

                  정리가 되는군요.. ^^;;

                  감사합니다!
                • 승쭈
                  감사합니다.!!!
                • 감사합니다
                • 코딩무뢰한
                  안녕하세요? 많은 도움이 되고 있습니다. 궁금한 점은 client 의 서비스에 여러 resource owner가 접속하여 사용 할 경우 1번 resource owner의 동의와 client ID, secret를 통해 받은 access code는 2번 resource owner가 접속시에는 소용이 없는 것 아닌지요? 그렇다면 결국 refresh token이라는 것이 왜 필요한지 잘 모르겠습니다. 어짜피 접속시마다 access token이 새로 부여될텐데 말이죠...
                  초보자의 질문이라 두서 없습니다.
                • 몽몽이
                  좋은강의감사합니다~
                • yoojat
                  저에게 정말 필요한 수업이었는데 ㅠㅠ 정말 감사합니다
                • eukrasie
                  좋은 강의 감사히 잘 봤습니다.
                버전 관리
                egoing
                현재 버전
                선택 버전
                graphittie 자세히 보기