我正在构建一个应用程序,它包含一个连接到我的 rails 应用程序的移动客户端(Android 本机应用程序)。我需要一种方法让用户使用 android 应用程序登录和注册我的 rails 应用程序。因此,我在我的 rails 应用程序上安装了门卫并设计了 gems,并按照此处的说明查看了工作原理。正如您在授权代码流页面中看到的那样,有多个步骤,例如注册客户端、请求授权、请求访问令牌。
我的问题是如何从我的 android 应用程序执行所有这些步骤。任何帮助深表感谢。谢谢
1 回答
For registration (sign up) you can create a method in the user controller that does just that. Or you can customise Devise's sign_up page to look better in a mobile view and do the registration in a webview in the app.
As for Doorkeeper, either follow the usual flow as linked by you or give it a simpler approach. What I did was to
activate the refresh token - this will allow a user to get his access token and his refresh token, token used to regenerate the access token once it expires. This way you don't retain the user's login registration on your app, just the tokens.
white label some apps in config/initializers/doorkeeper.rb by using the skip_authorization to allow auto authorisation of some particular apps. You can allow auto authorisation to all the apps but I'd recommend you just whitelist some of them:
skip_authorization do |client| whitelisted_apps = ['app1_id', 'app2_id'] whitelisted_apps.include? client.application.uid end
I hope this helps.