How to check the authorization status using android-evernote sdk? - android

Im developing an android application which uses evernote android sdk for some evernote process.
The login is successfull and authorization is also working.
How can I check if the authorization status is valid or invalid after the login.
Based on following method
com.evernote.client.android.EvernoteSession.isLoggedIn()
It only returns the login status.It returns true if login was succesfull otherwise it returns false.
In ios-evenote sdk they have the variable
in the class -ENSession.h
with the help of property isAuthenticated we can find the the authorization status.
Like that i want to know the authorization status.For instance I was logged in today and gave authorization for 1 day and did not logout.After that I closed my app without using the logout session.
Tomorrow I want to check the status of authorization. How can I do that? Is there is any method available in the evernote android sdk?

You can use:
EvernoteSession.getInstance().isLoggedIn()
to get the current authentication status of the user. Just make sure you are using the most up to date (v2+) version of the SDK (available here: https://github.com/evernote/evernote-sdk-android)
Multiple examples in the readme for the SDK utilize this method for the purpose you describe including this one: https://github.com/evernote/evernote-sdk-android/blob/master/README.md#creating-a-note-asynchronously

Follow the steps to get the session status whether it is active or not
check the login status
if login success means then call any api method that is listing the notebooks,etc
If it is success means session is valid otherwise invalid session
For instance sample code is given below
final SessionCheckingCallback callback_final = callback;
if (!mEvernoteSession.isLoggedIn()) {
Log.d(SESSION_CHECK_TAG, "Session expired.Session not logged in");
callback.onSessionExpired();
}
try {
AsyncNoteStoreClient asyncNoteStoreClient = mEvernoteSession.getClientFactory().createNoteStoreClient();
asyncNoteStoreClient.listNotebooks
(
new OnClientCallback<List<Notebook>>() {
#Override
public void onSuccess(List<Notebook> data) {
//Session valid
callback_final.onSessionSuccess();
}
#Override
public void onException(Exception exception)
{
exception.printStackTrace();
if (exception instanceof EDAMUserException)
{
Log.d(SESSION_CHECK_TAG, "exception is EDAMUserException");
EDAMUserException eDAMUserException = (EDAMUserException) exception;
if (eDAMUserException.getErrorCode() == EDAMErrorCode.AUTH_EXPIRED) {
Log.d(SESSION_CHECK_TAG, "Session expired");
callback_final.onSessionExpired();
} else {
Log.d(SESSION_CHECK_TAG, "Session not expired");
callback_final.onSessionSuccess();
}
}
else
{
Log.d(SESSION_CHECK_TAG, "exception is not EDAMUserException");
Log.d(SESSION_CHECK_TAG, "Session expired");
callback_final.onSessionExpired();
}
}
}
);
} catch (Exception ex) {
ex.printStackTrace();
Log.d("Session check", "session expired due to exception ");
callback.onSessionExpired();
}

Related

Not able to login after updating android studio to 2.3

So I updated my android studio from 2.2.3 to 2.3 and tried to run my app and since then I am not able to login to my apps parse back end. The exception is
com.parse.ParseException: java.lang.IllegalArgumentException: value == null
this is the method from where this exception has been triggered.
public static void loginUser(String username, String password, final ParseLoginCallbacks callback) {
Log.d(TAG, "loginUser: "+username);
Log.d(TAG, "loginUser: "+password);
final Integer num = 5;
ParseUser.logInInBackground(username, password, new LogInCallback() {
public void done(ParseUser user, ParseException e) { //user is null here with e = exception mentioned above. username and password has correct value.
if (user != null) {
// The user is logged in.
if (callback != null){
callback.loginSucceeded(user);
Log.d("myTag", "Log in succeded");
}
}
else {
// Signup failed. Look at the ParseException to see what happened.
if (callback != null)
callback.loginFailed(e);
Log.d(TAG, "Parse user login failed");
Log.d(TAG, e.toString());
}
}
});
}
Same code I run in my collegues studio version 2.2.3 and its perfectly working fine. I am trying to see issues regarding new update 2.3 issues with parse but not able to find anything.
Any advices....????
IllegalArgumentException is thrown because you pass wrong argument to the function.IAE
You should first reassure that your username or password is not null. Then pass it to the Parse if both variables are not null.
found the solution for now. While initializing Parse I had to put an empty string for client key, before it was null... but still it makes me think that all these one year in the app it never caused any issue and with 2.3 android studio it does, but nevertheless now it works fine

Getting the logged in user info from ADAL on android

I am working with ADAL from
https://github.com/Azure-Samples/active-directory-android
My code mimics the sample very close
mAuthContext.acquireToken(ToDoActivity.this, Constants.RESOURCE_ID,
Constants.CLIENT_ID, Constants.REDIRECT_URL, Constants.USER_HINT,
new AuthenticationCallback<AuthenticationResult>() {
#Override
public void onError(Exception exc) {
if (mLoginProgressDialog.isShowing()) {
mLoginProgressDialog.dismiss();
}
Toast.makeText(getApplicationContext(),
TAG + "getToken Error:" + exc.getMessage(), Toast.LENGTH_SHORT)
.show();
navigateToLogOut();
}
#Override
public void onSuccess(AuthenticationResult result) {
if (mLoginProgressDialog.isShowing()) {
mLoginProgressDialog.dismiss();
}
if (result != null && !result.getAccessToken().isEmpty()) {
setLocalToken(result);
sendRequest();
} else {
navigateToLogOut();
}
}
});
I pass in the user's email address, but if the user changes it and uses a different one the ADAL library on the onSuccess never tells me the user changed it. The AuthenticationResult has a field calls mUserInfo that that should contain user's first name/last name email etc.
But for me every successful login mUserInfo=null.
Anyone know how to get ADAL to return a fully populated mUserInfo object?
thanks
Tom
Userinfo is constructed from the ID_token retuned from the server. In case of adfs blue (3.0), it does not return an ID_token and hence you cannot truly know what user signed in at the IDP. Adfs threshold supports ID_token if you can upgrade.

Linking Facebook to ParseUser

I am not sure if I am missing a step in the process of linking a Facebook account to an existing Parse User.
This is the code I am using, as per Parse.com
if (!ParseFacebookUtils.isLinked(currentUser)) {
ParseFacebookUtils.linkWithReadPermissionsInBackground(currentUser, getActivity(), null, new SaveCallback() {
#Override
public void done(ParseException ex) {
if (ex == null) {
if (ParseFacebookUtils.isLinked(currentUser)) {
Log.d("MyApp", "Woohoo, user logged in with Facebook!");
}
} else {
Log.e(TAG, ex.getMessage());
}
}
});
}
I am not receiving any type of error, and it will successfully open up the Facebook activity to accept/cancel giving access to my application. The issue that I am finding, is that the authData section inside my User record, inside Parse, is never populated.
What am I doing wrong that my Parse User is not receiving any authData?
Do you happen to add the code to fragment?
If you do that, you should consider about onActivityForResult.
As you know, onActivityForResult is not called normally.

Parse - isNew() always returns false when logging in with Facebook

When attempting to login and signup through Facebook, the method isNew() somehow always returns false, even if the "_User" table is empty or if the user is logging in for the first time (signing up).
According to the docs:
isNew(): Indicates whether this ParseUser was created during this session through a call to ParseUser.signUp() or by logging in with a linked service such as Facebook.
Here's the code:
private void loginWithFacebook() {
ParseFacebookUtils.logInWithReadPermissionsInBackground((Activity) getContext(), null, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
if (user.isNew()) {
onLoginListener.onSignupWithFacebook();
} else {
onLoginListener.onLoginWithFacebook();
}
} else if (e != null) {
handleException(e);
}
}
});
}
Other people have come across similar problems and fixed it, but the solutions they've come up with don't apply to my case:
Facebook login with Parse always returns false in user.isNew() Android
Facebook Login not working properly (Parse)
User.isNew() returns false when it should return true
Apart from that, everything else seems to be working fine. The user data is created and stored on the table just like it normally should. Any suggestions?
remove enableAutomaticUser() if you have written in Application or BaseActivity class
docs says that this method will Enables automatic creation of anonymous users.
remove except this three and try may help you.!!
FacebookSdk.sdkInitialize(getApplicationContext());
Parse.initialize(this,getString(R.string.parse_app_id),getString(R.string.parse_client_key));
ParseFacebookUtils.initialize(this);

Quickblox QBChatservice login logs jabber ID but callback and getPrivateChatManager aren't working

Whenever I use the following to login to QBChatService:
chatService.login(user, new QBEntityCallbackImpl() {
#Override
public void onSuccess() {
// success
Log.d("CHAT_READY", String.valueOf(chatService.isLoggedIn()));
try {
chatService.startAutoSendPresence(60);
} catch (SmackException.NotLoggedInException e) {
e.printStackTrace();
}
}
#Override
public void onError(List errors) {
// errror
AlertDialog.Builder dialog = new AlertDialog.Builder(ctx);
dialog.setMessage("chat login error: " + errors).create().show();
}
}
I observe the following log output:
D/QBASDK﹕ Connecting to chat..
D/QBASDK﹕ Connected. Login to chat, currentUser JID: myUserID-myAppID, resource: someRandomString
Which I assumed was an indication that login was successful. However, the onSuccess and onError functions of the callback are not called.
Also, Calling
QBChatService.getInstance().getGroupChatManager()
returns null.
Am I missing something on setting up chat service properly?
The first thing I did was allow QBChatService to print debug logs. Doing that revealed that a password not verified error was being returned by the service.
Next, I tried using the BaseService token as password but same result. It seems you can't just use user.SetID, do QBAuth.login(user...) and then set Password in the onSuccess when using facebook login.
In the end, I had to store the facebook access token, login again with facebook (sign in using social provider) before setting the password with the BaseService token to login to the chat service successfully.

Categories

Resources