Implementing oauth in android - android

I am new to android environment and have been trying my hands on different things in android.
I don't know whether this is possible or not, but I want to achieve some sort of functionality as follow:
when my app starts, the main activity allows the user to login using facebook or Google.
I have used Facebook SDK for login and logout functionality for facebook.
(I am still using deprecated methods)
Now when user logins using either facebook or google , I want my app to automatically navigate to other activity.
Question 1: How should I do this ? using both Facebook and Google?
This activity has four buttons. Using these , user can navigate to different parts of the App.
One of these buttons is Settings.
Whenever user clicks on this button, the App should show the profile information of the user.
The information that my First Activity gathers when it prompts the user to login.
Question 2: How should I manage user data from their accounts between different activities??
(like their email or Profile picture etc)
Question 3:
Should i access the data in first login activity or when user clicks on the "Setting " button? (in the next activity) Is it possible? how? I think I can use Access Tokens like (getAccessToken() in facebook sdk??) that i get in first activity?
Question 4:
Can i save the data when user first logs in, so that i don't have to fetch the data every time he logs in?
How should I do this?
And between one session (Login and logout) I don't want my app to fetch data everytime he user clicks on "Settings" button..... how should i save data? SharedPreferences ??
Any sort of Comments, Remarks (Related only) , Articles, tutorials, projects , views, suggestions are most welcome!!
I am quite confused.
thankyou!!

Question 1: How should I do this ?
Use an Intent to go to the next Activity on successful login.
Question 2: How should I manage user data from their accounts between
different activities?? (like their email or Profile picture etc)
Store the details in SharedPreferences when the user logs in and make sure to clear the SharedPreferences on logout.
Question 3: Should i access the data in first login activity or when
user clicks on the "Setting " button? (in the next activity) Is it
possible? how? I think I can use Access Tokens like (getAccessToken()
in facebook sdk??) that i get in first activity?
Question 4: Can i save the data when user first logs in, so that i
don't have to fetch the data every time he logs in? How should I do
this?
And between one session (Login and logout) I don't want my app to
fetch data everytime he user clicks on "Settings" button..... how
should i save data? SharedPreferences ??
Yes, SharedPreferences is the solution to these. Here is something you could do :
when the user logs in for the first time, store the access tokens and their expiry in SharedPreferences.
after that, every time, just check if the session is valid or not by using the access tokens. If session is valid, then use the details stored in your Preference file. If the session has expired, fetch the tokens again and update your SharedPreference file.
Here is an excellent video tutorial series on Android Facebook SDK and the best part for you is that he uses SDK 2.0 (the deprecated one), like you are using!

Related

How to login(or check if a user is already logged in ) in wordpress from my own android app

I have designed a simple android app which based on some input from the user redirects the user to certain part of my wordpress site.
The problem that I am facing is that before that, I need to check if the user is already logged in and if not to give him the possibilit to log in.
I checked around and everyone is talking about the android app but I need the login to be done from my own app.
Any idea/orientation how that can be done?
You'll need to make use of SharedPreferences which will login user at first then when the app is closed and launched again, it'll not tell the user to login. SharedPreferences will collect key values in strings and boolean then it'll save user data when the app is relaunched in the onCreate method of an Activity or in the onCreate view of a Fragment.
Remember to commit after each preference. Try to check out this YouTube playlist link:
Playlist Link
and search for SharedPreferences tutorials

When user login in one mobile, the same credientals should not login in another device in android

As I want to implement the login function same as whatsapp . If the user login in one device using (email and password) .The same login should not happen in another device.How to implement this functionality in android
In my application whenever the user login ,the status value will be change as 1 in database, when the same user if login in another device means it will show popup, already exist,If the previous user logout means value changed as 0.
But my doubt suppose if the user as logged in and uninstall the app means again he cant able to login again because the value changed as 1.
For the above situation how to handle.Please someone help me.
I am not sure, but the following idea may work.
As also mentioned here, save every users' phone ID to your DB as well. (I am also adding the code for helping you, but as I mentioned code was written by someone else in the link above)
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
Then, check if the user is trying to log in by using that device which has its ID stored in your DB. If this is the case, directly log in the user. This shows that user deleted the application without logging out.
If the user uninstalled the program in the other device and then enters the application from another device, ask the user to log in again. After user logs in, save the current device's ID in your DB. For security issues, maybe you can store the old logged in device's ID and model and more.
I hope I clearly explained to you the idea. Let me know if that helped or not.
Have a nice week!
You need to maintain session for this. when user logins create and return one sessionId for that user. for all request there after need to pass that sessionId. if same user login from another device overwrite previous sessionId with new one. so that based on that first users request will be invalid. and one user is login on one device only

Google Signin Android App, How to check to make sure the User has not revoked the authorization?

This question is about the new GoogleSignInApi explained here.
Suppose I go through the steps and I acquire the email, first name, last name and for good measure an Id.
Suppose I save all this information on the device (either via Preferences or via SQLite) so that in future I don't need to ask the user for his authorisation again.
The question is how to make sure that the Id and the info is still valid,
Perhaps by next time, the user has revoked his authorisation, or that he has changed some of the profile info.
Now before you answer that I have to use SilenSignIn, let me say, that silent sign in won't work. Because for the Initial signin I use another Activity called through startIntentForResult after I get the profile I close that activity, I don't want to have to call that activity again, because the point of saving the information is not to call the activity again.

re loggin using third party( google, FB,Twitter)

This is my first major android application, so sorry if this was asked before, but cant seem to find something relevant to help me.
I am developing an android app, where i have managed to add the google sign in method, using the google's guide. My problem now is how to enable my app, to read the users loggin information after they terminate it and relaunch it. Based on some posts here and other guides (which i cant recall now) what i did was storing a boolean variable in SharedPreferences where it states whether the user is logged in or not. boolean isLoggedIn = sharedPreferences.getBoolean(GoogleLogged, false);
I am loading the SharedPreferences file on the splash screen and make the choice of displaying the login layout or not. other than that I dont save anything else from the login process. I guess that I need to store a token, taken from the google servers, but cant find any relevant solutions.
You want to use the social login using Twitter,Fb and Google.While logging through all of these you will get different user ids as the user id for the same user for google,Fb and twitter will be different ,if you want create a user id for your users and want to use that for further communications.Get the user details from these apis like name,email and respective user id and the method of login which social medium they used for login and respective to that create a web service which will provide the user id for your usercase and store that userid in shared preferences.So in the splash screen you can check that user has logged in or not.

How can i check if i have already logged in salesforce in android application?

Situation:
1. i have user login form which is used by user to login into application, at the same time we login into salesforce.
2. next time when user opens the application then he is not supposed to get the login form,but directly the main screen.
3. in this main screen i have a button call sync which retrieves data from SF, but for that i have to check if i am already logged in SF.
If you're not using oAuth you probably should look at using that instead. However, assuming that you're not, why not just try and make a request for the user's own user record using the session ID you have, and if that fails because the session ID is invalid then you can do the login again?
There's likely to be a way of testing other than by doing this, so I'd encourage you to read the documents for the API.

Categories

Resources