简体   繁体   English

使用OAuth进行移动和使用我自己的API的网站的正确方法是什么?

[英]What is the correct way to use OAuth for mobile and website consuming my own API?

I have a question more related to the way OAuth 2 is working but since using IdentityServer to implement OAuth I think it's relevant. 我有一个问题与OAuth 2的工作方式有关,但由于使用IdentityServer实现OAuth,我认为这是相关的。 I could not find an answer anywhere. 我无法在任何地方找到答案。

I'm building a website and a mobile app that consumes my own API. 我正在建立一个消耗我自己的API的网站和移动应用程序。 Each user of my app will have a username and password, that will give him access to the app/website and though the API to his information. 我的应用程序的每个用户都将拥有一个用户名和密码,这将使他能够访问应用程序/网站,并通过API访问他的信息。

I'm not sure about the right way to handle the flow for user login: 我不确定处理用户登录流程的正确方法:

  1. On the website I have my own designed login form. 在网站上我有自己设计的登录表单。 I don't want to move the user to my auth server to login, and then have him approve the information he gives - he is the user on my system - I have access to all information - kida like facebook has a login and access to the informatio - they don't ask what you're willing to give them. 我不想将用户移动到我的auth服务器进行登录,然后让他批准他给出的信息 - 他是我系统上的用户 - 我可以访问所有信息 - 像facebook这样的kida有登录和访问权限信息 - 他们不会问你愿意给他们什么。 So is implicit really the way for this? 那隐藏真的是这样的吗?
  2. On the mobile app I also have a login form and now I read here ( https://tools.ietf.org/html/draft-ietf-oauth-native-apps-10 ) that the OAuth approach is to have the login in a WebView?? 在移动应用程序上,我还有一个登录表单,现在我在这里阅读( https://tools.ietf.org/html/draft-ietf-oauth-native-apps-10)OAuth方法是登录一个WebView ?? Doesn't look like facebook login is in a WebView on their mobile app. 看起来Facebook登录不在他们的移动应用程序的WebView中。
  3. The approach I was first lookin at is the Resource Owner. 我第一次看到的方法是资源所有者。 Users will login, get the token and the refresh token and can start working against my APIs. 用户将登录,获取令牌和刷新令牌,并可以开始使用我的API。 But storing my client_id and secret on the mobile app? 但是将我的client_id和秘密存储在移动应用程序中? on the website javascript files? 在网站上的javascript文件? doesn't feel right. 感觉不对。 I can of course make a call to an API that will mask those and be a proxy to the login process... but... (read #4). 我当然可以调用一个API来掩盖那些并成为登录过程的代理......但是......(阅读#4)。
  4. In the future I would like to allow access for third-party developers. 将来我想允许第三方开发人员访问。 For them to allow login for users of my system I will use the implicit flow. 为了让他们允许我的系统用户登录,我将使用隐式流程。 Also, I plan for those developer accounts to have restricted API access (for example, the number of calls to the API will be limited by plan). 此外,我计划让这些开发者帐户具有受限制的API访问权限(例如,对API的调用次数将受到计划的限制)。 What prevents those developers from asking for the username and password of their account on my system on their website, getting the response from my servers with the access token and refresh token, and using my API however they want, without restrictions, and having access to the entire user profile? 什么阻止那些开发人员在他们的网站上的系统上询问他们帐户的用户名和密码,从我的服务器获取访问令牌和刷新令牌的响应,然后使用我们想要的API,没有限制,并且可以访问整个用户个人资料?
  5. Lets say I'm sticking to the resource owner flow, receiving back from the server a token and a refresh token. 让我们说我坚持资源所有者流,从服务器接收令牌和刷新令牌。 What should I store on the mobile device and how? 我应该在移动设备上存储什么以及如何存储? What should be stored in the browser and how? 什么应该存储在浏览器中以及如何? the refresh token? 刷新令牌? and each time he opens the app get a new updated token with that refresh token? 每次他打开应用程序时都会获得一个带有刷新令牌的新更新令牌?

Edit 编辑

Just to clarify, because I find a lot of lectures and articles that explain the process from an API consumer point of view (ie. the third-party developer): I am the API owner and the auth server owner, I'm the owner of the user accounts (they are my users of my services), I'm also my own consumer (though the website and the mobile app), and in the future I want to enable third-party developers to allow my users to login with their accounts of my service (kinda like Facebook or Google) 只是为了澄清,因为我发现很多讲座和文章从API消费者的角度来解释这个过程(即第三方开发者):我是API所有者和auth服务器所有者,我是所有者用户帐户(他们是我服务的用户),我也是我自己的消费者(虽然是网站和移动应用程序),并且将来我想让第三方开发者允许我的用户登录他们对我服务的描述(有点像Facebook或谷歌)

You're correct that you shouldn't store the client_secret in your app, but I doubt you will get around storing the client_id . 你是不对的,你不应该在你的应用程序中存储client_secret ,但我怀疑你会绕过存储client_id You could disable the consent screen for your app as well, and build a native login view. 您也可以为应用禁用同意屏幕,并构建本机登录视图。 You need to store the access_token and the refresh_token on the device (maybe encrypted in a database) if you don't want the user to login everytime they use your app. 如果您不希望用户每次使用您的应用程序时都登录,则需要在设备上存储access_tokenrefresh_token (可能在数据库中加密)。

As for problem 4, you could do the following: 至于问题4,您可以执行以下操作:

  1. Embed the client_secret in your (web) app client_secret嵌入到您的(Web)应用程序中
  2. Set up which hosts have access to your api on the IdentityServer 设置哪些主机可以访问IdentityServer上的api
  3. The IdentityServer generates a salt and sends it to the client IdentityServer生成salt并将其发送到客户端
  4. The client calculates a session_secret using hash(ip_address + session_salt) 客户端使用hash(ip_address + session_salt)计算session_secret hash(ip_address + session_salt)
  5. The client uses the session_secret and the client_secret for the API call 客户端使用session_secretclient_secret进行API调用
  6. Server validates the hash and client_secret 服务器验证hashclient_secret

It's nearly impossible to completely prevent someone from using your API. 完全阻止某人使用您的API几乎是不可能的。 But you should add various rate limiting methods, such as limiting IP addresses, API calls etc. But nothing will stop someone decompiling your app and accessing your client_id . 但是你应该添加各种速率限制方法,例如限制IP地址,API调用等。但没有什么能阻止某人反编译您的应用并访问您的client_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以为我自己的WebSite公开一个API…但是使用oAuth进行api身份验证? - Is it possible to expose an API for my own WebSite … but use oAuth for the api authentication? 关于使用OAuth使用自己的API的问题 - Questions About Consuming Your Own API with OAuth Code Igniter-使用我自己的API和授权 - Code Igniter - Consuming my own API and authorisation 为Web应用程序使用自己的API - 使用OAuth2进行身份验证过程 - Consuming own API for web app - Authentication process with OAuth2 我自己的客户端是否需要通过OAuth与我的REST API交互? - Is there a need for my own client to interface with my REST API through OAuth? 如何使用Linkedin Javascript API作为我自己网站的登录? - How can I use the Linkedin Javascript API as a login for my own website? 如何为我的网站一实施OAuth并将其用于网站二 - How to implement OAuth for my website one and use it for website two 如何在自定义API .net核心中正确使用OAuth 2.0以使用外部API - How to get OAuth 2.0 right for consuming external APIs in my Custom API .net core 应该使用什么类型的第 3 方身份验证 (OAuth) 来登录用户以拥有 API - What type of 3rd party authentication(OAuth) should be used to sign in users to own API 在我的类视图中使用 Oauth2 令牌允许某些用户仅访问他自己的用户数据? - Use Oauth2 token in my classview to allow some user access only his own user data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM