I am trying to get a valid Google oauth2 token for a user that has logged in through Firebase. I need a Google token so I can authenticate this user through other Google services (not just Firebase).
I am currently using the firebase-admin for this on a server and passing that user's Firebase token to nodejs. I'm doing something like this:
admin.auth().verifyIdToken(tokenId)
.then((decoded) => {
const uid = decoded.uid;
console.log(tokenId);
admin.auth().createCustomToken(uid).then((t) => {
console.log(t);
})
}
However neither the token I'm passing to the admin or the custom token seems to work for other Google services. I'm able to create a custom token, just not sure if or how I can use that to get a google oauth token for that user.
Related
I try to migrate from AWS JavbaScript SDK V2 to V3.
I want to retrieve the user groups a logged-in Cognito user (form an identity pool) belongs to.
In V2, this was as easy as looking in the ["accessToken"].payload['cognito:groups'] element of the sign-in response.
In V3 it's not part of the response. How do I get this piece of information in V3?
I am using Amplify Auth, so I use the following code:
const session = await Auth.currentSession();
let idToken = session.getIdToken();
console.log(idToken.payload["cognito:groups"]);
You should just switch to "idToken" instead of "accessToken" in the sign-in response, and that should do the trick.
I'm planning to write Firebase function on Authentication user creation. My goal is to get the long live access token for the Facebook user page's.
To do that I need user access token in Firebase functions. Tried below..,
exports.saveLongLiveToken = functions.auth.user().onCreate(event => {
console.log(event.providerData)
})
I though providerData will have the information about the Facebook credentials, but not instead I got only undefined.
Note: In the event, I got below
{ data:
{ displayName: 'Rob',
email: 'xxx#xyz.com',
metadata:
{ createdAt: 2017-08-23T18:58:34.000Z,
lastSignedInAt: 2017-08-23T18:58:34.000Z },
photoURL: 'http...',
providerData: [ [Object] ],
uid: 'xfff...' },
eventId: 'xxx',
eventType: 'providers/firebase.auth/eventTypes/user.create',
notSupported: {},
resource: 'projects/fiobot-4fa94',
timestamp: '2017-08-23T18:58:34.571Z',
params: {} }
If you are signing in with Firebase Auth signInWithPopup/Redirect, you will only get the access token after sign-in. Firebase Auth does not store it for you (neither does it store the Facebook refresh token). You will need to save it in the Database where only the specified user can access it and the Admin SDK via Firebase Functions can allow you access it. If you think Firebase Auth should manage OAuth tokens for providers, please file a request via Firebase Support channels.
If this is essential for your app functionality, you can use the Facebook API to sign in the user and get a Facebook access token and sign in with firebase.auth().signInWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken))
Facebook client API can manage the OAuth token for you. You can also use a backend OAuth node.js library to refresh Facebook tokens via the Firebase Functions whenever you need one. You would need to get the Facebook refresh token though.
I am working on Excel Web Add-In. I am using OfficeDev/office-js-helpers library for authenticating user. Following code is working fine. But I don't know how to get user's email, user name etc.
Is there any function available in OfficeDev/office-js-helpers through which I can get user info ?
if (OfficeHelpers.Authenticator.isAuthDialog()) {
return;
}
var authenticator = new OfficeHelpers.Authenticator();
// register Microsoft (Azure AD 2.0 Converged auth) endpoint using
authenticator.endpoints.registerMicrosoftAuth('clientID');
// for the default Microsoft endpoint
authenticator
.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft)
.then(function (token) {
/* My code after authentication and here I need user's info */ })
.catch(OfficeHelpers.Utilities.log);
Code sample will be much helpful.
This code only provides you the token for the user. In order to obtain information about the user, you'll need to make calls into Microsoft Graph API. You can find a full set of documentation on that site.
If you're only authenticating in order to get profile information, I'd recommend looking at Enable single sign-on for Office Add-ins (preview). This is a much cleaner method of obtaining an access token for a user. It is still in preview at the moment so it's feasibility will depend on where you're planning to deploy your add-in.
Once you have the Microsoft token, you can send a request to https://graph.microsoft.com/v1.0/me/ to get user information. This request must have an authorization header containing the token you got previously.
Here is an example using axios :
const config = { 'Authorization': `Bearer ${token.access_token}` };
axios.get(`https://graph.microsoft.com/v1.0/me/`, {
headers: config
}).then((data)=> {
console.log(data); // data contains user information
};
I am working on a login flow with FirebaseUI for web.
Facebook provider is invoked with scope(permission) user_likes.
After user approves the app and permissions, login is successful.
However, I am now wondering how to retrieve the user_likes via a graph API call to facebook directly.
Essentially, where to retrieve the required parameters from successful firebase auth so as to make a successful graph api retrieving user_likes list.
You need to get the facebook auth credential from the signInSuccess callback. You can then use the OAuth credential to query the facebook api:
'callbacks': {
'signInSuccess': function(currentUser, credential, redirectUrl) {
// Do something.
// Return type determines whether we continue the redirect automatically
// or whether we leave that to developer to handle.
// Credential is in credential.accessToken
return false;
}
}
I am trying to authenticate a user in my ionic app using the authWithOAuthToken() method in Firebase. I am getting this error -> {"code":"INVALID_CREDENTIALS","details":"{\"providerErrorInfo\":{}}"} with my firebase ref, when I try with another firebase ref, it works.
In Firebase Error Listing, INVALID CREDENTIALS means
The specified authentication credentials are invalid. This may occur when credentials are malformed or expired.
But I am not passing any credential to the method
var Ref = new Firebase('https://<firebase-ref>.firebaseio.com');
Ref.authWithOAuthToken('facebook', '<facebook token>', function(error, authData) {
if (error) {
console.log('Login Failed!', JSON.stringify(error));
} else {
console.log('Authenticated successfully with payload:', authData);
}
});
Anybody encountered this before?
Go to Facebook Tab inside Login & Auth in firebase project, Copy and paste Credentials from your facebook developer app and try running your app, if you have already entered your details, make sure they are correct , if it still doesn't work check by creating a new facebook developer app and again enter the details in firebase