Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use doorkeeper with an android client?

I'm building an application which consists of a mobile client (Android native app) that will connect to my rails application. I need a way for users to signin and signup to my rails app using the android app. So I installed doorkeeper and devise gems on my rails app and followed the instructions here to see how things work. As you can see in the authorization code flow page there are multiple steps such as registering the client, requesting authorization, requesting the access token.
My question is how do I perform all these steps from my android app. Any help is much appreciated. Thanks

like image 651
Akshay Takkar Avatar asked Sep 30 '22 13:09

Akshay Takkar


1 Answers

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

  1. 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.

  2. 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.

like image 191
eduard.bulai Avatar answered Oct 03 '22 10:10

eduard.bulai