Firebase Google Authentication Says: Access blocked: This app’s request is invalid - javascript

I have linked my domain in the firebase authentication, and I have allowed access for auth too.
If you would like to try it, here is the link
https://colesprojects.ml/signin/
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
alert(user.displayName);
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.email;
// The AuthCredential type that was used.
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
alert(errorMessage);
});
});
Here is my code if I am doing something wrong.

Looking at the error, it seems to me you didn't add your domain to your Authorized redirect URIs.
Go to the GCP console Credentials configuration, in the OAuth 2.0 Client IDs section select your app and add your redirect url to the Authorized redirect URIs section at the bottom (here your redirect URI would be https://colesprojects.ml/__/auth/handler as stated in the error).

Related

The request is not valid for the application's 'userAudience' configuration

Tried to login via microsoft provider but after providing my email in the popup I m getting following error:
error_description=The request is not valid for the application's 'userAudience' configuration. In order to use /common/ endpoint, the application must not be configured with 'Consumer' as the user audience. The userAudience should be configured with 'All' to use /common/ endpoint.
I m not sure where exactly I need to set it as consumer. Here is my code
const provider = new OAuthProvider("microsoft.com");
signInWithPopup(auth, provider)
.then((result) => {
console.log("doLogin then section");
// User is signed in.
// IdP data available in result.additionalUserInfo.profile.
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
console.log("doLogin", error);
});
it's common error
Create a new App Registration with supported account type as "All Microsoft account users" works with any errors.

Error: auth.sendSignInLinkToEmail is not a function

const firebase = require("firebase-admin");
const auth=firebase.auth();
// create user in firebase data
var actionCodeSettings = {
// URL you want to redirect back to. The domain (www.example.com) for this
// URL must be in the authorized domains list in the Firebase Console.
url: 'https://www.example.com/finishSignUp?cartId=1234',
// This must be true.
handleCodeInApp: true,
dynamicLinkDomain: 'example.page.link'
};
// [END auth_email_link_actioncode_settings]
app.get("/firebase/api/createUser",function(req,resp){
auth.sendSignInLinkToEmail("sagar#gmail.com",actionCodeSettings)
.then((userCredential) => {
// Signed in
var user = userCredential.user;
console.log("user created :"+user);
resp.send("--"+userCredential);
// ...
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
// ..
});
});
It gives me an error. the setting I already enable in firebase.
What is issue here?
This function was written in the firebase cloud function.
Sending emails and SMS messages to a user with Firebase Authentication is only possible with the client-side SDKs.
You're using the Admin SDK, which does not have this functionality, as it would be too prone to abuse.
So you will have to implement this functionality in the client-side application code, using the regular client-side/Web SDK for Firebase Authentication.

Firebase google sign in pop up window flashes and never signing in using Vuejs?

I have used google sign in popup method in vuejs. In live google sign in pop up window flashes and never signed in. But everything works fine in local.
Here is firebase google sign in & sign up method code:
const database = firebase.initializeApp(config);
const firestore = database.firestore();
var provider = new firebase.auth.GoogleAuthProvider();
database.signIn = async (email, password) => {
try {
await firebase.auth().signInWithPopup(provider).then((result) => {
// This gives you a Google Access Token. You can use it to access Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
console.log("user",user.displayName);
console.log('result google',result.user);
// ...
store.commit("setCurrentUser", result.user);
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
return true;
} catch (error) {
return error;
}
}
Tried by changing chrome pop up, cookies setting nothing works. Any help much appreciated please...
If it's working locally, you should make sure your hosting domain is registered with Google OAuth.
In Firebase console:
Develop -> Authentication -> Sign-in method -> Authorized domains
And add your domain to the list. It may take some time to verify.
If that doesn't work, try logging error.message for more information.
After updating firebase it works fine. npm i firebase#latest..

Firebase Auth check if new user on Facebook login

I am creating a web app using Firebase auth to authenticate my users and a MongoDB database to store some relevant user information specific to my site. I am trying to add Facebook as another means of authentication.
Logging in with Facebook is working, but what I want to do is intercept the user generation/authentication with Firebase to check if Firebase is creating a new user on a first-time Facebook login. This way if a new user is being created in Firebase I can also create a new user in my mongo database (essentially handling a signup). My facebook login function looks like this:
handleFacebookLogin() {
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
// check if new user here
// handleNewFacebookUser()
this.props.update(user);
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
});
}
I couldn't find anything that allowed me to check if a new user was being generated in the Firebase docs. It seems to silently handle new Firebase auth user generation when logging in through Facebook for the first time. If there is no built-in way for Firebase to handle this I will just check if the user exists in my database, but I wanted to be sure there wasn't a simpler alternative.
You can detect if a user is new or existing as follows:
firebase.auth().signInWithPopup(provider)
.then(function(result) {
console.log(result.additionalUserInfo.isNewUser);
})
.catch(function(error) {
// Handle error.
});
For more on this refer to the documentation.

Firebase Facebook login with redirect returning null email

If I have the following code
function facebookSignin(){
var provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);
}
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
var token = result.credential.accessToken;
}
var user = result.user;
console.log(result);
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
console.log(errorMessage);
});
I'm trying to get the email from Facebook login however when I print the user object i get a null email. I have included a screenshot of the user object printed in the console
Check the content of firebase.auth().currentUser.providerData[0].email. That should show the facebook email. It is possible you have enabled "multiple accounts per email" in the Firebase console. The default for new projects is single account per email. For migrating Firebase projects from the previous version, they are set to "multiple accounts per email". That will only set firebase.auth().currentUser.email for password accounts. For federated accounts, it is set to null. There is another possibility that the facebook account you are using is a phone number account or has chosen not to disclose the email.

Categories

Resources