What's the right OAuth 2.0 flow for a mobile app

后端 未结 5 1437
离开以前
离开以前 2020-11-28 00:41

I am trying to implement delegated authorization in a Web API for mobile apps using OAuth 2.0. According to specification, the implicit grant flow does not support refresh t

5条回答
  •  無奈伤痛
    2020-11-28 01:29

    Unfortunately, I don't think there is a clear answer to this question. However, here are the options that I've identified:

    • If it is ok to ask the user for his/her credentials, then use the Resource Owner Password Credentials. However, this may not be possible for some reasons, namely

      • Usability or security policies forbid the insertion of the password directly at the app
      • The authentication process is delegated on an external Identity Provider and must be performed via an HTTP redirect-based flow (e.g. OpenID, SAMLP or WS-Federation)
    • If usage of a browser based flow is required, then use the Authorization Code Flow. Here, the definition of the redirect_uri is a major challenge, for which there are the following options:

      • Use the technique described in https://developers.google.com/accounts/docs/OAuth2InstalledApp, where a special redirect_uri (e.g. urn:ietf:wg:oauth:2.0:oob) signals the authorization endpoint to show the authorization code instead of redirecting back to the client app. The user can manually copy this code or the app can try to obtain it from the HTML document title.
      • Use a localhost server at the device (the port management may not be easy).
      • Use a custom URI scheme (e.g. myapp://...) that when dereferenced triggers a registered "handler" (the details depend on the mobile platform).
      • If available, use a special "web view", such as the WebAuthenticationBroker on Windows 8, to control and access the HTTP redirect responses.

    Hope this helps

    Pedro

提交回复
热议问题