zoukankan      html  css  js  c++  java
  • 学习 OAuth2.0

     

    基于浏览器

    访问后跳到登录页面,登录成功后跳转到授权页面,授权成功后跳转到redirect_uri指定的地址。

    1.请求授权。

    http://localhost:8080/oauth/authorize?client_id=unity-client

    &redirect_uri=http%3a%2f%2fwww.baidu.com

    &response_type=code&scope=read

    • 地址是/oauth/authorize.
    • client_id表示厂商的唯一标识,在厂商申请资质时自动生成的。
    • redirect_uri回调地址,认证成功后带着code重定向该地址。
    • response_type响应类型。
    • scope权限范围。

    2.授权成功后回调地址

    http://localhost:8080/unity/dashboard.htm?code=zLl170

    • 地址是redirect_uri里配置的。
    • code临时授权码。

    3.通过code换取access_token

    http://localhost:8080/oauth/token?client_id=unity-client

    &client_secret=unity&grant_type=authorization_code

    &code=zLl170&redirect_uri=http%3a%2f%2fwww.baidu.com

    • 地址是/oauth/token
    • client_id表示厂商的唯一标识,在厂商申请资质时自动生成的,不可修改,全局唯一。
    • client_secret表示厂商的密码,在厂商申请资质时自动生成的,可以修改。
    • grant_type发放类型。
    • code授权成功后在回调地址里带的那个code。
    • redirect_uri回调地址,要与获取code的回调地址保持一致。

    4.获取access_token响应的数据

    {"access_token":"3420d0e0-ed77-45e1-8370-2b55af0a62e8",

    "token_type":"bearer","refresh_token":"b36f4978-a172-4aa8-af89-60f58abe3ba1",

    "expires_in":43199,"scope":"read"}

    • access_token我们要的就是这个token,以后带着这个token访问我们的系统就畅通无阻了。
    • token_type类型,还没搞懂具体含义。
    • refresh_token刷新token有效时间时用。
    • expires_in过期时间,单位还没搞懂。
    • scope权限范围,和申请时配置一致。

    5.获取access_token后访问资源 [GET]

    http://localhost:8080/unity/dashboard.htm?

    access_token=3420d0e0-ed77-45e1-8370-2b55af0a62e8

    • 以后就可以带着token访问我们的站点资源了,就好像用户登录后操作一样。

    6.刷新access_token [GET]

    http://localhost:8080/oauth/token?client_id=mobile-client&client_secret=mobile

    &grant_type=refresh_token&refresh_token=b36f4978-a172-4aa8-af89-60f58abe3ba1

    • 地址/oauth/token
    • client_id表示厂商的唯一标识,在厂商申请资质时自动生成的,不可修改,全局唯一。
    • client_secret表示厂商的密码,在厂商申请资质时自动生成的,可以修改。
    • grant_type发放类型。
    • refresh_token获取token时得到的。

    spring权限配置的要求

    用户有个角色可以访问/openapi 客户端有个角色可以访问/openapi 用户把自己的openapi的访问权限给客户端,客户端拿着token才能访问用户的/openapi

    已经实现OAuth2的一些开放平台


    Oauth2参考资料

  • 相关阅读:
    char类型细节
    Hibernate面试题
    线程
    IO流
    集合
    链表相关的一点东西
    正则表达式学习
    python中的变量域问题
    python的输出和输入形式
    python mutable 和 immutable
  • 原文地址:https://www.cnblogs.com/qyf404/p/4390325.html
Copyright © 2011-2022 走看看