美文网首页
OAuth2.0四种授权模式-1

OAuth2.0四种授权模式-1

作者: 程序男保姆 | 来源:发表于2022-04-05 22:54 被阅读0次
    • 授权码模式
      1)获取authorization_code授权码
      使用浏览器访问:
    http://localhost:7000/oauth/authorize?response_type=code&client_id=net5ijy&redirect_uri=http://localhost:8080&scope=all
    
    image.png

    2)获取token令牌
    使用curl命令获取token令牌

    curl --user net5ijy:123456 -X POST -d "grant_type=authorization_code&scope=all&redirect_uri=http%3a%2f%2flocalhost%3a8080&code=Q1dzfj"  http://localhost:7000/oauth/token
    
    image.png
    {
        "access_token": "547e258c-9c88-4130-a6d5-770b6b6ef3a4",
        "token_type": "bearer",
        "refresh_token": "19cf0168-913e-4f64-a766-72c0d43928ba",
        "expires_in": 43199,
        "scope": "all"
    }
    

    这样就获取到了token令牌,该token的访问权限范围是all权限,在12小时后失效。

    • 密码模式
    获取token令牌
    使用curl命令获取token令牌
    
    curl --user net5ijy:123456 -X POST -d "grant_type=password&username=admin&password=123456&scope=all" http://localhost:7000/oauth/token
    
    
    image.png
    {
        "access_token": "20d4f648-2ce4-4198-9f2a-025211efb689",
        "token_type": "bearer",
        "refresh_token": "9caccc03-5b81-48f9-a32e-45538c2f779c",
        "expires_in": 43199,
        "scope": "all"
    }
    
    • 隐藏式

    浏览器访问地址:

    http://localhost:7000/oauth/authorize?client_id=net5ijy&redirect_uri=http://localhost:8080/callback&response_type=token&scope=all
    
    

    请求参数列表:

    client_id=客户端id
    redirect_uri=回调url 一定要与授权服务器配置保持一致,否则得不到授权码
    response_type=token 简化模式必须是token
    scope=作用域 与授权服务器配置保持一致
    state=自定义串(可选)

    刷新
    http://localhost:7000/oauth/token?grant_type=refresh_token&refresh_token=25cee547-66a2-4a85-bbb1-e13d94e29f8e

    相关文章

      网友评论

          本文标题:OAuth2.0四种授权模式-1

          本文链接:https://www.haomeiwen.com/subject/zyylsrtx.html