How to hardcode a Google Account in Android? - android

So, I was using the Google Drive API in one of my applications and when the application starts it asks for Google Sign in and I have to sign in using the Google Account on which Drive API is enabled.
So then I can upload any file using my app to the drive.
But I wondered if I could sign in to that particular Google Account through the code itself, by putting the credentials inside the code.
So when I open the application it should automatically sign in to that Account which has Drive API enabled and then the Application can be used to upload any files to that particular drive.
Is this possible?

You actually do not need to hard code. First, you may check if you have an already signed in user by using this line of code:
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
If you already have one you pass the info of this user without even needing to sign in again. Or, there is another way called silent sign-in.
GoogleSignIn.silentSignIn()
With a silent sign in you won't be asked for credentials every time, once you sign in successfully. More info can be found here.

Related

How to submit PlayStore app access credentials for google sign in authentication

I have an app where a user needs to log in with a google account & purchase premium (play billing) for accessing premium features. Everything works perfectly.
Recently playstore force developers to submit app credentials to test if the app has certain functions which require authentication.
If my app has a normal email and password for auth then I'll submit to google play a test user's e-mail and password from my backend server. But now It's Google Sign in. I don't know any test google account which uses app reviewers. The doc has no information about that.
In this situation, should I have to submit my personal google account and password to review app authentication (because it was added to the test licence in the GooglePlay developer console)?
or there is some test google email account from (playstore app reviewer) for whitelisting on my server-side?
You Just need to tell them to "login using Google Account" in "Any other instruction" field, as shown below, you don't have to create a test account for this. I tried this many times before.
So I was stuck on this issue for about a whole month, I couldn't update my production app.
Google documentation clearly state that Note that you do not need to provide credentials if your app supports "Sign-in with Google,” which enables the crawler to log in automatically. However this was not the case for me.
I tried:
Going with the 1st option that - No special access is required. - Never worked
2nd option - Stating the the app requires Google login (didn't submit any credentials). - Never worked
Eventually, what worked was - I created another email account on my mobile device. Then submitted the credentials to Google.
Point to note - ensure the email account you create doesn't contain any 2 factor authentication or verification as this won't work.
I noticed that you do not need to do this in the case of a Google account.
If you see the pre-launch reports in the Google Play console, and watch the replay of the test, you will see that when the Google Play robot encounters the Google Account login screen, they will have an account with a #cloudtestlabaccounts.com email that they will use to login as seen on the below image:
As you can see, Google Play robots have Google accounts available to them to login and therefore you do not need to put as special access, unless if you are using non-Google accounts to login.
I personally use Google Accounts as login and never submitted any login information and they didn't have any issue with this.
I created a Google account specifically for app testing purposes. I use it for both Android and iOS. You submit the credentials for that account for review. After your app is approved, you can always change the password and just update the credentials when you submit the app for review again.
I tried submitting use "google login" in any other instructions field but it didn't work.
What worked was I created a demo google account and submitted the email and password. Also, wrote use "google login" in any other instructions.
hope it helps

Google authentication with email and password.

I am creating an application that uses google drive api, and requires authentication of a google account. The example on the quick start for using drive api for android uses google sign_in where user would be required to choose an account from the google accounts already added on the phone.
I dont want user to choose there own account. I want to add the account the api would be used in from code, such that files would be accessed from my own specified accounr not that of the user of the app. But I cant seam to find any sign_in or authentication form apart from the case when user is to choose an account.
Please can this be done? And if so how?
Answer would be simple No, you can do that but you have to use different API than that of Google's one. Google will ask to choose from account as it is added in implicit intent.

oAuth token for multiple services

I have a Dropbox account which was created by logging in via the Google account. So, my Dropbox account is linked to the Google account.
I have an android application and my users can create their accounts either via Google/Facebook.
The question is,if it is possible for the user to login to our app once via his Google Account, and then using these same underlying google's credentials the user automatically gets logged in to Dropbox Account [Maybe a simple 'OK' button authentication is needed], so that they need not enter their login credentials twice?
I am planning to implement this using oAuth. Any guidance on whether is possible or not will be helpful. I am not expecting code but some guidance.
In general what you are asking is not possible.
The credentials/assertions that Google issues are for a specific app and only that app should accept those credentials.
So when a user signs into your app, you get a credentials from Google that says this is for your app. Also Dropbox accepts credentials from Google that was issued for Dropbox. Your app can not convert one into another (if it could this would be a big security issue e.g. one app could sign into a user's all other apps/account that accept Google credentials for expalple bank account).
What you want to do is integrate with the OAuth Apis that are from Dropbox and when the user is going through them try to prefill information to make the flow easier. If you send "user email" to Google OAuth flow (to get user signed into dropbox) for the same user (who is signed in) they could go through the flow easily. https://developers.google.com/identity/protocols/OpenIDConnect#sendauthrequest

Android Sign in to app using Google plus without making app on console

I want to know if it is possible to sign in to my app using Google Plus without making app on Google Console?
You can't do it without creating app in console, since your app would need access tokens in order to login Google Plus. While creating an app on console, Signing Certificate FingerPrint (SHA1) is required to authorize your app plus explicitly enabling of this feature for your app.
So in short, you won't be able to login Google Plus, unless you authorize your app in Google Console.
Specify basic developer profile information about yourself or your company on the accounts detail page.This identifies you to Google Play and your customers. You can go back at any time to edit the information and change your settings.
Google uses the Google Developers Console to configure access for apps to communicate with the Google APIs.
Your web app must use the Google Sign-In button to prompt your web site users to download your app the first time that they sign in. This feature is enabled by adding the apppackagename parameter to your sign-in button.
*
Hence,it is not possible to sign in to your app using Google Plus
without making app on Google Console.
*
It is no way to sign in to your app without using Google Console.
If you just don't like the console, you can try this:
https://developers.google.com/mobile/add
starting from here:
https://developers.google.com/identity/sign-in/android/start

Accessing google drive in android

I am making and android app which downloads a particular file from Google Drive, reformats the data in the file and then displays it to the user.I have used the Google Drive API. In the app, instead of asking the User to select an account, I want to hard code a Google Account Username and Password through which the file on the Drive is downloaded. This should happen without the user's interaction.
You do not need to hardcode your account data - just use Service account
How to use Google Drive SDK in Android project with hardcoded credentials - here the solution.

Categories

Resources