I've been trying to add Google Sign-In in Android but have a couple of doubts.
From the Android documentation Integrate google sign in android
In the server side authentication part Client Id is required which is OAuth 2.0 web application client ID for your backend server.
From android's documentation:
Get your backend server's OAuth 2.0 client ID If your app authenticates with a backend server or accesses Google APIs from your backend server, you must get the OAuth 2.0 client ID that was created for your server. To find the OAuth 2.0 client ID
From my understanding the flow would be:
- Android app will get the
auth codefrom google which will be passed to the backend. - The backend will get the
access tokenwith theauth codefrom the android app and theclient secret. - With the
acess tokenwe get the user's information and theaccess tokenis saved in the database.
My doubts are:
- I read somewhere on StackOverflow that we need to create two OAuth client one for Android and one for Web Application. Is this True?
- Django Rest Auth Login View need to have one
redirect_urldefined but I don't understand what would be theredirect_uriin case of Android device or we need to pass this URL while getting theauth codefrom Google. - On OAuth Playground I put my backend's
client idandclient secretand got theauth codeand when I passed thisauth codeto my login view I was getting theredirect_uri_mismatchbut If I putredirect_url = 'developer.google.com'It works, I guess theauth codecontains host information from where it is generated that's why this should be the same asredirect_urlin my rest-auth view but then for android what it should be?
Here is my Google Login View.
class GoogleLogin(SocialLoginView):
adapter_class = GoogleOAuth2Adapter
client_class = OAuth2Client
callback_url = 'localhost:8000' # What this should be?
Please ask for more information If I forgot to put any.
I am using this django-rest-auth
Some helpful link -
- https://github.com/Tivix/django-rest-auth/issues/262#issuecomment-256562095 # It says callback URL could be a fake one but I get
redirect_uri_mismatch