zoukankan      html  css  js  c++  java
  • ASP.NET OAuth Authorization

     

    What I don't fully understand is the use of ClientId and Secret vs Username and Password. The code I pasted generates a token by username and password and I can work with that token (until it expires), but when I try to get a refresh token, I must have the ClientId.

    Also, if a token expires, the correct way is to send the refresh token and get a new token? What if the refresh token gets stolen? isn't it the same as a username & password getting stolen?

    In OAuth2 is essential to authenticate both the user and the client in any authorization flow defined by the protocol. The client authentication (as you may guess) enforces the use of your API only by known clients. The serialized access token, once generated, is not bound to a specific client directly. Please note that the ClientSecret must be treated as a confidential information, and can be used only by clients that can store this information in some secure way (e.g. external services clients, but not javascript clients).

    The refresh token is simply an alternative "grant type" for OAuth2, and, as you stated correctly, will substitute the username and password pair for a User. This token must be treated as confidential data (even more confidential than the access token), but gives advantages over storing the username & password on the client:

    • it can be revoked by the user if compromised;
    • it has a limited lifetime (usually days or weeks);
    • it does not expose user credentials (an attacker can only get access tokens for the "scope" the refresh token was issued).

    I suggest you to read more about the different grant types defined in OAuth 2 checking in the official draft. I also recommend you this resource I found very useful when firstly implemented OAuth2 in Web API myself.

    Sample requests

    Here are two request examples using fiddler, for Resource Owner Password Credentials Grant:

    and for Refresh Token Grant:

    https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/

  • 相关阅读:
    POJ 1163 状态转移
    POJ 1143 记忆化搜索+博弈论
    POJ 1083
    POJ 1018
    HDU 3572 Dinic
    HDU 3549 Dinic
    配置JDK环境变量配置及path和classpath的作用
    frameset 框架整体退出登录的问题
    java计算时间差及比较时间大小(转)
    Android—Http连接之GET/POST请求
  • 原文地址:https://www.cnblogs.com/chucklu/p/10346388.html
Copyright © 2011-2022 走看看