Firebase authentication error code 5 - android

I am trying to login to firebase using google login. The google login is successful. After this I invoke authWithOAuthToken and I am getting below error.
Due to another authentication attempt, this authentication attempt was aborted before it could complete. Error Code = -5
Few other questions:
Do we need to call authWithOAuthToken at all (after google login)? I noticed I could add data to firebase database even without call.
If above is not required, how can I get uid (which is firebase user id same across providers). At present we can get this from AuthData.
Code Snippet Below.
baseFirebaseRef.authWithOAuthToken("google", oAuthTokenStr, new Firebase.AuthResultHandler() {
// #Override
public void onAuthenticated(AuthData authData) {
// the Google user is now authenticated with your Firebase app
Log.d(currentScreenName, "------On Firebase Authentication. Success");
}
// #Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
Log.e(currentScreenName, "------Error On Firebase Authentication......." + firebaseError.getDetails() +
"Error Message = "+ firebaseError.getMessage() + " Error Code = "+ firebaseError.getCode()) ;
}
});

I called unauth() and then called authWithOAuthToken().

Related

Amazon Cognito Push Sync Using Google Log-In And Firebase Cloud Messaging: Failed To Subscribe To Dataset

I'm trying to use Amazon Cognito Sync to remotely store and retrieve information about my user, and for that information to be synced across all devices that that user is logged into.
I'm following the tutorial here which shows how to create Dataset objects and how to use its get(), put(), and synchronize() methods.
After getting that working, I tried following the tutorial here which shows how to register a device for push notifications and subsequently subscribe to a Dataset that you want to keep synced. However, when I call
cognitoSyncManager.subscribeAll()
I get the following exception:
com.amazonaws.mobileconnectors.cognito.exceptions.SubscribeFailedException: Failed to subscribe to dataset
at com.amazonaws.mobileconnectors.cognito.internal.storage.CognitoSyncStorage.subscribeToDataset(CognitoSyncStorage.java:360)
at com.amazonaws.mobileconnectors.cognito.DefaultDataset.subscribe(DefaultDataset.java:604)
at com.amazonaws.mobileconnectors.cognito.CognitoSyncManager.subscribe(CognitoSyncManager.java:332)
at com.amazonaws.mobileconnectors.cognito.CognitoSyncManager.subscribeAll(CognitoSyncManager.java:319)
Caused by: com.amazonaws.services.cognitosync.model.ResourceNotFoundException: Failed to subscribe to dataset USER_INFORMATION, endpointArns do not exist (Service: AmazonCognitoSync; Status Code: 404; Error Code: ResourceNotFoundException; Request ID: 7e681e01-a872-11e7-9e5f-01c7f0419773)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:712)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:388)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199)
at com.amazonaws.services.cognitosync.AmazonCognitoSyncClient.invoke(AmazonCognitoSyncClient.java:864)
at com.amazonaws.services.cognitosync.AmazonCognitoSyncClient.subscribeToDataset(AmazonCognitoSyncClient.java:663)
at com.amazonaws.mobileconnectors.cognito.internal.storage.CognitoSyncStorage.subscribeToDataset(CognitoSyncStorage.java:357)
at com.amazonaws.mobileconnectors.cognito.DefaultDataset.subscribe(DefaultDataset.java:604) 
at com.amazonaws.mobileconnectors.cognito.CognitoSyncManager.subscribe(CognitoSyncManager.java:332) 
at com.amazonaws.mobileconnectors.cognito.CognitoSyncManager.subscribeAll(CognitoSyncManager.java:319) 
In my Android app, I'm authenticating the user using Google Sign-In, which gives me the token that I need when creating my Cognito Credentials Provider, and I'm using Firebase Cloud Messaging for getting the token needed by Cognito Sync Manager. Here's the snippet of my code which results in the exceptions:
new Thread(new Runnable()
{
#Override public void run()
{
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(getContext(), Utilities.getString(R.string.aws_cognito_identity_pool_id), Regions.US_EAST_1);
Map<String, String> loginsMap = new HashMap<>();
loginsMap.put("accounts.google.com", GoogleLoginManager.getInstance().getToken());
credentialsProvider.setLogins(loginsMap);
credentialsProvider.refresh();
cognitoId = credentialsProvider.getIdentityId();
isLoggedIn = !cognitoId.equals("");
if(isLoggedIn)
{
CognitoSyncManager cognitoSyncManager = new CognitoSyncManager(getContext(), Regions.US_EAST_1, credentialsProvider);
try
{
cognitoSyncManager.registerDevice("GCM", FirebaseInstanceId.getInstance().getId());
}
catch(RegistrationFailedException exception)
{
Log.e(exception);
}
catch(AmazonClientException exception)
{
Log.e(exception);
}
if(cognitoSyncManager.isDeviceRegistered())
{
try
{
cognitoSyncManager.subscribeAll();
}
catch(SubscribeFailedException exception)
{
Log.e(exception);
}
catch(AmazonClientException exception)
{
Log.e(exception);
}
}
}
}
}).start();
Any idea what I'm doing wrong? Following the tutorials and navigating the developer console have been a bit of an enigma for me, and I feel like there must be some core concept that I'm just not getting.
I finally figured it out. When calling cognitoSyncManager.registerDevice() I was passing FirebaseInstanceId.getInstance().getId() as the token instead of FirebaseInstanceId.getInstance().getToken(). Bleh.
Also, before calling cognitoSyncManager.registerDevice("GCM", FirebaseInstanceId.getInstance().getId()); I now call cognitoSyncManager.unregisterDevice(). Apparently, if you call registerDevice() in a previous run of the app and the registration wasn't actually successful, the CognitoSyncManager class still stores in SharedPreferences that it's registered, and thus will block all future calls to registerDevice() until unregisterDevice() is called.

Microsoft ADAL authentication on Android

I'm trying to create a SyncAdapter for Microsoft calendars and the first step is Authentication. i'm using com.microsoft.aad:adal:2.0.4-alphaand using this code for first authentication:
getAuthenticationContext().acquireToken(
mContextActivity,
Constants.SCOPES.split(" "),
null,
Constants.CLIENT_ID,
Constants.REDIRECT_URI,
PromptBehavior.Auto,
new AuthenticationCallback<AuthenticationResult>() {
#Override
public void onSuccess(final AuthenticationResult authenticationResult) {
if (authenticationResult != null && authenticationResult.getStatus() ==
AuthenticationResult.AuthenticationStatus.Succeeded) {
dependencyResolver = new ADALDependencyResolver(
getAuthenticationContext(),
resourceId,
Constants.CLIENT_ID);
token = authenticationResult.getToken();
UserInfo userInfo = authenticationResult.getUserInfo();
if (userInfo != null) {
userIdentifier = new UserIdentifier(userInfo.getUniqueId(),
UserIdentifier.UserIdentifierType.UniqueId);
}
}
}
#Override
public void onError(Exception t) {
Log.e("initialize", "onError : " + t.getMessage());
result.setException(t);
}
}
);
this works perfectly and after entering username and password i can get token.
BUT this is for sync adapter and at some point i need to get token silently. so i used this code:
public void getTokenSilent() {
getAuthenticationContext()
.acquireTokenSilent(Constants.SCOPES.split(" "),
Constants.CLIENT_ID,
userIdentifier,
new AuthenticationCallback<AuthenticationResult>() {
#Override
public void onSuccess(
AuthenticationResult authenticationResult) {
UserInfo userInfo = authenticationResult.getUserInfo();
}
#Override
public void onError(Exception e) {
Log.e("getTokenSilent", "onError : " + e.getMessage());
}
});
}
After executing this code i got the error:
AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED Prompt is not allowed and failed to get token: ver:2.0.4-alpha
onError : Refresh token is failed and prompt is not allowed
how can i resolve this error and get or refresh token silently?
tnx in advance.
If you want to get the token silently, there are two ways for using Azure AD V2.0 endpoint.
First, acquire the access token and refresh token interactively, then get the access token in the cache or renew the access token using refresh token via acquireTokenSilent method.
Second is that the Azure AD V2.0 endpoint also support the Client Credentials flow(refer here) which normally used for the service daemon application. However the MSAL for android doesn't support this flow at present. You need to implement it yourself. You can follow this article about detail of this flow. And this flow only works for the Azure AD account.

Android Firebase's createUser failing: handler always calling onError

I'm trying to create a new user in Firebase but onError is constantly being called by my ValueResultHandler:
public void onSignUpComplete(String email, String password) {
Firebase ref = new Firebase(Constants.FIREBASE_URL); // this is "https://subdomain.firebaseio.com/"
ref.createUser(email, password, new SignUpResultHandler());
}
class SignUpResultHandler implements Firebase.ValueResultHandler<Map<String, Object>> {
#Override
public void onSuccess(Map<String, Object> StringObjectMap) {
Toast.makeText(getApplicationContext(), "Created User!", Toast.LENGTH_SHORT().show();
}
#Override
public void onError(FirebaseError firebaseError) {
Toast.makeText(getApplicationContext(), "Failed to create user! " +
firebaseError.getDetails(), Toast.LENGTH_SHORT).show();
}
}
I always get the toast "Failed to create user!" and an empty return from getDetails().
Some extra information: Email and password authentication is enabled in Firebase and my manifest has a uses-permission for "android.permission.INTERNET". I have firebase-auth:9.4.0, firebase-core:9.4.0, firebase-database:9.4.0 and firebase-client-android:2.5.2 as dependencies (and play services). I have my google-services.json file in the app folder and the plugin applied in gradle. I'm running the app in a connected device but this also fails on an emulator.
Looks like you're following old Firebase documentation.
new Firebase() method is deprecated as of May 18, 2016 and the url will be handled by the json file, so we do not need to define it. Here is the link for steps with new documentation: Create a password-based account.

Firebase authWithOauthToken is not working

I am developing an app in Android using firebase.I have created the login activity where i have a method that logs user in when they pass the credentials(user creation is already done).Then i will save the token recieved in onAuthenticated callback so that i can log user in automatically next time when he/she opens the app without asking to enter the credentials.
Here is the code
private void loginWithPassword(final String email, String password) {
progressDialog.show();
FirebaseConnections.getConnection().authWithPassword(email, password,
new Firebase.AuthResultHandler() {
#Override
public void onAuthenticated(AuthData authData) {
// Authentication just completed successfully :)
IGStorePreference.getInstance().saveString(Constants.TOKEN, authData.getToken());
IGStorePreference.getInstance().saveString(Constants.UID, authData.getUid());
IGStorePreference.getInstance().saveString(Constants.PROVIDER, authData.getProvider());
dismissProgressDialog();
}
#Override
public void onAuthenticationError(FirebaseError error) {
// Something went wrong :(
dismissProgressDialog();
Snackbar.make(parentView, error.getMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
And then i check onCreate whether we have token token to log user in
private void checkIfTokenExistAndLogin() {
if (IGStorePreference.getInstance().isPrefExists(Constants.TOKEN)) {
progressDialog.show();
String provider = IGStorePreference.getInstance().getString(Constants.PROVIDER);
String token = IGStorePreference.getInstance().getString(Constants.TOKEN);
FirebaseConnections.getConnection().authWithOAuthToken(provider, token, new Firebase.AuthResultHandler() {
#Override
public void onAuthenticated(AuthData authData) {
IGStorePreference.getInstance().saveString(Constants.TOKEN, authData.getToken());
IGStorePreference.getInstance().saveString(Constants.UID, authData.getUid());
IGStorePreference.getInstance().saveString(Constants.PROVIDER, authData.getProvider());
dismissProgressDialog();
}
#Override
public void onAuthenticationError(FirebaseError firebaseError) {
dismissProgressDialog();
Snackbar.make(parentView, firebaseError.getMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
}
But the problem is that i am getting an error while login user with authWithOAuthToken.Please help what i am missing.
This is the error i recieve everytime.
FirebaseError: Invalid authentication credentials provided.
authWithOAuthToken is used to login with a social provider. For example, user signs in with Google and gets an OAuth token returned from Google. Then app sends this OAuth token to Firebase auth server via authWithOAuthToken. User can log in after server verifies the OAuth token.
In your case, user logged in with email/password. The token you received was a Firebase auth token issued by Firebase auth server not an OAuth token issued by social provider.
Please refer to the doc for details: https://firebase.google.com/support/guides/firebase-android#sign_a_user_in_with_a_social_provider_numbered

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