Unable to authenticate with Microsoft using Firebase - android

I'm trying to implement authentication with Microsoft using Firebase in my app. I followed the steps mentioned in the tutorial https://firebase.google.com/docs/auth/android/microsoft-oauth.
Following are the code snippets from my application -
MSAuthManager.java
public void loginOutlook(Context context) {
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
Task<AuthResult> pendingResultTask = firebaseAuth.getPendingAuthResult();
if (pendingResultTask == null) {
OAuthProvider.Builder provider = OAuthProvider.newBuilder("microsoft.com");
provider.setScopes(asList(SCOPES));
firebaseAuth.startActivityForSignInWithProvider((Activity) context, provider.build())
.addOnSuccessListener(this)
.addOnFailureListener(this)
.addOnCanceledListener(this);
}
}
AndroidManifest.xml
<activity android:name="com.microsoft.identity.client.BrowserTabActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https://**********.firebaseapp.com/__/auth/handler"
android:host="auth" />
</intent-filter>
</activity>
Note - I have already authenticated the user with Google sign-in using Firebase on the Login Screen.
However, when I start the authentication process, a custom tab launches takes me to the Microsoft login page and then automatically closes and redirects me back to my app with the following error -
FirebaseAuthWebException: The web operation was canceled by the user.
Could anyone please tell me what am I missing here?

I had the same problems, and for me it's because the entered password is wrong so -> The web operation was canceled by the user.
You have to managed saved password or clear cache and data for chrome or samsung internet browser.

Related

flutter: HttpException: Failed Forbidden from the twitter plugin

I'm trying to implement twitter login in my app but it doesn't work, returning an errorMessage in the AppResult object. Does anyone know a solution?
The packages I use are
twitter_login: ^4.2.3
firebase:
firebase_core: ^1.11.0
firebase_auth: ^3.3.5
Twitter config (User authentication settings page):
OAuth 1.0a enabled (is it the proper one for the plugin?)
Request email from users: disabled
App permissions: Read
Callback URI: https://project-name.firebaseapp.com/__/auth/handler
webiste url: https://www.google.com/
besides that everything is empty
Firebase config:
twitter auth enabled
api key set (checked it like 10 times)
api secret set (same thing)
Android manifest:
inside the activity tag:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<!-- Registered Callback URLs in TwitterApp -->
<data android:scheme="https" android:host="app-name.firebaseapp.com" />
<!-- host is option -->
</intent-filter>
after the activity tag:
<meta-data android:name="flutterEmbedding" android:value="2" />
The code itself:
final twitterLogin = TwitterLogin(
apiKey: '123 it's the same one',
apiSecretKey: 'proper one',
redirectURI: 'https://app-name.firebaseapp.com/__/auth/handler');
final authResult = await twitterLogin.login();
print(authResult.errorMessage); // prints out HttpException: Failed Forbidden
The code opens the link with the authentication, but after clicking on "authorize app", it returns to the app with the errorMessage "HttpException: Failed Forbidden"
Also, the authToken and the authTokenSecret are both null.
If you need any additional information, please let me know!
Your getting Forbidden http exception. So, in the official documentation it says -
The request is understood, but it has been refused or access is not allowed. An accompanying error message will explain why.
And the solution is given as -
Check that your developer account includes access to the endpoint you’re trying to use. You may also need to get your App allowlisted (e.g. Engagement API or Ads API) or sign up for access.
You can check - Twitter API Documentation
Hope it helps.
So, after a little bit of digging I found the answer to my question. In order to make it work I did the following:
changed the android scheme to appname://
removed the android host
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<!-- Accepts URIs that begin with "example://gizmos” -->
<!-- Registered Callback URLs in TwitterApp -->
<data android:scheme="appname" />
<!-- host is option -->
</intent-filter>
changed the redirect url inside the twitter config to appname://
got elevated access for the twitter portal
used the loginV2 function along with OAuth2 instead of OAuth1
Future<UserCredential> _signInWithTwitter() async {
// Create a TwitterLogin instance
final twitterLogin = TwitterLogin(
apiKey: '123',
apiSecretKey: '1234',
redirectURI: 'appname://');
// Trigger the sign-in flow
final authResult = await twitterLogin.loginV2();
print(authResult.toMap());
// Create a credential from the access token
final twitterAuthCredential = TwitterAuthProvider.credential(
accessToken: authResult.authToken!,
secret: authResult.authTokenSecret!,
);
// Once signed in, return the UserCredential
return await FirebaseAuth.instance
.signInWithCredential(twitterAuthCredential);
}
Didn't use the callback provided by firebase at all (this is mentioned in the README too, but I'm too stupid to check)

Flutter Spotify Api Authentication

I need to authenticate user in my Flutter app which uses Spotify api.
I use flutter_web_auth to open WebView and let user login there.
I can't make it to return to app.
In Spotify Dashboard i have callback Uri set to: https://spotifydata.com/callback
final callbackUrl = "https://spotifydata.com/callback";
void _authenticateSpotfy() async {
final url = Uri.https('accounts.spotify.com', '/authorize', {
'response_type': 'code',
'client_id': clientID,
'redirect_uri': 'https://spotifydata.com/callback:/',
'scope': 'user-read-private user-read-email',
});
final result = await FlutterWebAuth.authenticate(
url: url.toString(), callbackUrlScheme: callbackUrl);
}
AndroidManifest.xml
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
<intent-filter android:label="flutter_web_auth">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https://spotifydata.com/callback" />
</intent-filter>
</activity>
I have tried other answers on Stack but they don't seem to work.
As mentioned in Spotify's API docs, authentication redirects the user to the defined redirect_uri on successful request. Trying to log-in on https://spotifydata.com/, it has redirect_uri set as redirect_uri=https%3A%2F%2Fspotifydata.com%2Fsongdata. Make sure that the defined redirect_uri matches the callback scheme configured in the Manifest file since this enables the app to handle the redirect URL via the intent-filter.

Deeplink opened from Facebook App goes to PlayStore

The deeplinking works fine from WhatsApp, Slack and even Facebook Messenger but doesn't work from the Facebook App itself.
In the branch.io Link Settings I did enable:
✓ Always try to open app
✓ Enable App Links + SHA256 Cert Fingerprints
Changed to custom Link Domain: sharing.kptncook.com
successfully authenticated the "Facebook Install Ads"
Facebook developer settings:
Packagename, class name and hashes are correct(Facebook login also works fine)
✓ SSO is activated
✓ Deep-Link is activated
Android App Versions:
Facebook Messenger: 126.0.0.9.84
Facebook: 133.0.0.19.83
Example link: sharing.kptncook.com/pIbQ/FKktug85TE
Activity part of Manifest:
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<data android:scheme="kptncook" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="sharing.kptncook.com" />
<data android:scheme="http" android:host="sharing.kptncook.com" />
</intent-filter>
</activity>
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Activity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
}
}, this.getIntent().getData(), this);
}
#Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
Additional info: In the emulator some links won't open and some does. If I send a link that doesn't work from the emulator to a real device it works on the real device.
What am I doing wrong?
Update:
New shared links work now on the Real device in both Facebook Messenger and Main App. But if I open the exact same link in the messenger on an emulator it redirects to "r31v.test-app.link..." and doesn't show anything except a toast "Can't load page". It's so frustrating. Any ideas how to debug it?
Alex from Branch.io here:
Facebook deep linking is one of the hardest things to debug — they intentionally don't want users to leave their app, wherever possible.
A few notes for debugging:
The domain r31v.test-app.link is your original link domain. You customized this to sharing.kptncook.com, but there are times when Branch needs to use both to handle certain edge cases. You need to add the following lines to your Manifest:
<data android:scheme="https" android:host="r31v.test-app.link" />
<data android:scheme="https" android:host="r31v-alternate.test-app.link" />
Other than the above, your in-app configuration implementation looks fine.
It's possible something is funky with your Dashboard configuration. Branch has separate Test and Live environments, and you're currently using the Test one. It's important to make sure you haven't split your implementation between values from both sides.
Deep linking behavior frequently doesn't work correctly in the emulators. It's always best to test with real devices, because results from emulators are usually not reliable.
Facebook sometimes caches the App Links tags, which means you may get unpredictable results when opening a URL that has just been shared, or when re-sharing a URL that has been posted before with different data.
Feel free to reach out to our Integrations team any time with questions!

How to open the android app when user try to hit dynamic link in mobile browser

I have created dynamic links using firebase console. I have a local app (app not yet on google play store) installed on my device.
This is the code in manifest file for handling dynamic links.
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- [START link_intent_filter] -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="<code>.app.goo.gl/"
android:scheme="https"
android:pathPattern=".*" />
</intent-filter>
<!-- [END link_intent_filter] -->
</activity>
This is intent handler in activity
// [START build_api_client]
// Build GoogleApiClient with AppInvite API for receiving deep links
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(AppInvite.API)
.build();
// [END build_api_client]
// [START get_deep_link]
// Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
// would automatically launch the deep link if one is found.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// [START_EXCLUDE]
// Display deep link in the UI
//((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
// [END_EXCLUDE]
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
// [END get_deep_link]
when i open dynamic link in mobile browser, it is not redirecting me to app. instead opening the link in mobile browser itself.
How to open the app when user try to hit dynamic link in mobile browser?
There are some problems with both your url and your manifest. The "link" parameter needs to contain also the scheme, so with minimum changes it should be:
https://<code>.app.goo.gl/?link=https://google.com&apn=<package name>
(note the added https://) and when using that link your manifest should look like:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="google.com"
android:scheme="https"
android:pathPattern=".*" />
</intent-filter>
You can test your app with the full url before creating the short url on the firebase web page. This helps you ensure you get the app right before creating the short url for real use.
When using http/https schemes, android should first ask whether you want to open browser or your app. I prefer using "al" with app specific scheme to opening a view on my app.

Facebook deep link never return data after app was installed in Android

I try to use FB deep link to get referral info after App installed when I clicked in deep link which was posted at FB. But I received deep link data only if app already installed.
As follow by this doc
https://developers.facebook.com/docs/applinks/android
Application should receive data from deep link, after app has been installed.
But native FB application send to GooglePlay only :
market://details?id=my.app.package&referrer=utm_source=apps.facebook.com&utm_campaign=fb4a&utm_content=%7B%22app%22%3A0%2C%22t%22%3A1436879844%7D
There is no info from deep link
And one first launch I try use in my launch screen next methods
AppLinks.getTargetUrlFromInboundIntent
and AppLinkData.fetchDeferredAppLinkData
but they get me null.
Step by step
I have created hosted api links for android. Where include all possible data for android https://developers.facebook.com/docs/graph-api/reference/v2.0/app/app_link_hosts
Then by FB SDK post this link.
Remove my application
Click on my post with deep link in native FB application
FB ask me to install app. And I have installed app from GooglePLay
Expected :
After install receive deep link data on start app.
But if use method described at FB Docs I did not receive any info
A heads up that I helped build Branch (branch.io), a linking tool that helps with deep linking through the Play Store. We've had a ton of trouble getting Facebook's methods to work reliably as well. If you use a Branch deep link to host your Facebook App Links, it works 100% of the time through page posts, ads and invites. We have a server to server integration with Facebook, but if that fails, we fall back to our fingerprinting mechanism where we match a browser fingerprint to a device fingerprint. (More on that here)
Here's a description of how to get setup so that Branch hosts your Facebook App Links and deep links through install:
Head to start.branch.io to get your Branch key and configure your link routes
Add in the io.branch.sdk.android library from Maven Central
Setup your manifest for deep linking. You'll start with this:
<application>
<!-- Other existing entries -->
<activity
android:name="com.yourapp.SplashActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Add application subclass so that Branch can monitor for lifecycle changes to detect new deep links.
<application
android:name="io.branch.referral.BranchApp">
Add your intent filters to receive the deep link when the app is already installed
<intent-filter>
<data android:scheme="yourapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Add your Branch key
<meta-data android:name="io.branch.sdk.BranchKey" android:value="your_key_here" />
The final Manifest should look like this:
<application
android:name="io.branch.referral.BranchApp">
<!-- Other existing entries -->
<activity
android:name="com.yourapp.SplashActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="yourapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<meta-data android:name="io.branch.sdk.BranchKey" android:value="your_key_here" />
</application>
Register to receive parameters from Branch deep link click. This is frequently put in onStart of the Activity that you want to use for deep link routing.
Branch branch = Branch.getInstance(getApplicationContext());
branch.initSession(new BranchReferralInitListener(){
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// ... insert custom logic here ...
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
Lastly, to you can create Branch-hosted Facebook App Links in 100 different ways. Here's how to create them dynamically from your app:
Branch branch = Branch.getInstance();
JSONObject obj = new JSONObject(); obj.putString("foo", "bar");
branch.getShortUrl(obj, "sms", "share", new BranchLinkCreateListener() {
#Override
public void onLinkCreate(String url, BranchError error) {
Log.i("MyApp", "Ready to share my link = " + url);
}
});
Happy linking!

Categories

Resources