Sign In With Google - Function onSignIn - google-signin

Currently I'm using the Google Sign-In (Legacy) in one of my asp.net apps.
I'm trying to migrate over to the Sign In With Google button since the legacy will be discontinued in 2023.
I can get everything to work except for the below function. I need to grab some profile info for the asp.net app using the new Sign In With Google api.
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}
any help would be appreciated

User profile information is in the base-64 encoded JWT returned to your callback in the credential field of the CredentialResponse object. The previous link has a list of fields and meanings. You may find jwt.io a help during prototyping, paste the returned ID token credential value to decode.

Related

Using transaction on the database is creating and quickly deleting data at the given path

I have been learning and got some grip over firebase for a while now.
I am building a blog posts webapp (provided in official firebase examples) as a learning example;
I want to also add custom notifications system so that users can view notifications when logged in.
Whenever a user likes or comments on a blog post a data path is created under the post's author uid node as follows:
--user-notifications
----uid1
--------postid
------------notif: 'notification text'
------------postId: postId
------------viewed: false
------------createdAt: 'some date'
----uid2
--------postid
------------notif: 'notification text'
------------postId: postId
------------viewed: false
------------createdAt: 'some date'
Instead of sending a seperate notification for every like or comment I wanted to implement facebook's type of notification where all the likes for a particular post comes in a single notification . For example: john, kate and others liked your post or jane, todd and others commented on your post.
For this mentioned scenario I am using transactions as follows:
var sendCustomNotification = function(fromUID, recieverUID, userName, actionText, postID){
const ref = firebase.database().ref("user-notifications/" + recieverUID + "/" + postID);
if(fromUID !== recieverUID){
ref.transaction(function(obj){
if(obj){
//if notification is not viewd by the user
if(obj.viewed){
obj.notif = userName + actionText;
obj.viewed = false;
}else{
//if notification is viewd by the user the the user's names gets added into one
obj.notif = userName + ' and more ' + actionText;
}
}else{
ref.set({
notif: userName + ' '' + actionText,
statusId: postID,
viewed: false,
createdAt: formatDate(new Date())
});
}
return obj;
})
}
};
I use this sendCustomNotification() inside the code where the user comments or likes the post
now the problem is:
When a user comments or likes the sendCustomNotification() is called and in the realtime database a node is created or updated as expected but it gets deleted immediately again.
Dont't know what is the reaaon for this behaviour

meteor-shopify User Creation/ Login after Auth callback

Assuming I want to create users upon authorizing the app, how would I grab their email during the onAuth callback...? Looks like the callback assumes the user is already logged in. Am I thinking about it correctly?
I noticed when installing the Fishbowl Prizes app, after auth I can click on the accounts tab and see that all my account info is pre-populated from my shopify store account (name, email, address, etc).
I'm not sure if I should go by the title or the content of the post in terms of answering your question, so I'll provide a very simple example of how to get the info from the API and do something with it here.
I have provided a more in depth answer related specifically to grabbing the details from the API for user account creation here: https://github.com/froatsnook/meteor-shopify/issues/15#issuecomment-177413630
Looks like the callback assumes the user is already logged in.
The userId param is undefined if there is no user. If your onAuth operations don't need to do anything with the user, you can just leave it out of the params. In your case you'll just want to handle it conditionally using an if/else block:
if(!userId){
// do stuff
} else {
// do other stuff
}
On to the example of grabbing those details from the API:
All the prepopulated information you are seeing is available from the Shopify API in the shop object. You already have the access token when onAuth callbacks are fired, so you can just grab it from the API immediately after you have inserted the shop's Keyset.
For the sake of simplicity, in this example we'll assume the user already exists and is logged in. In your server-side onAuth callback (after you have inserted the keyset) you can do something like this to add those fields to the user's profile object:
Shopify.onAuth(function(access_token, authConfig, userId) {
var shopUUID = uuid.new(); // Not secure to name keyset same as the shop!
Shopify.addKeyset(shopUUID, {
access_token: access_token
});
var api = new Shopify.API({
shop: authConfig.shop,
keyset: shopUUID
});
// get the Shop object from the API
var shopObj = api.getShop();
var userInfo = {
'profile.name': shopObj.shop_owner,
'profile.email': shopObj.email,
'profile.phone': shopObj.phone,
'profile.shopName': shopObj.name
};
Meteor.users.update({_id: userId}, {$set: userInfo})
});
Then you can use them in templates like this:
{{currentUser.profile.name}} or {{currentUser.profile.email}}
Or in functions like so:
var realName = Meteor.user().profile.name
or
var userEmail = Meteor.user().profile.email etc
For a more about using this data for user creation, see my explanation here:
https://github.com/froatsnook/meteor-shopify/issues/15#issuecomment-177413630

How to post on my facebook page from my website using Facebook App keys created from my facebook account?

Below is the code i am using to achieve this functionality, and i have successfully posted it to my facebook wall from my website but i am not able to post to my facebook page?
How can i get page access token using FaceBookClient() in c# SDK?
var client = new FacebookClient();
dynamic token = client.Get("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAPI"].ToString(),
client_secret = ConfigurationManager.AppSettings["FacebookAPIKey"].ToString(),
grant_type = "client_credentials"
});
client.AccessToken = token.access_token;
dynamic parameters = new ExpandoObject();
parameters.title = detail.Title;
parameters.message = GetDescription(detail.Description, detail.Content);
parameters.link = "http://test.com/blog" + detail.RelativeLink;//HttpContext.Current.Request.IsLocal ? "http://test.com/blog" + detail.RelativeLink : HttpContext.Current.Request.Url.Authority + "" + detail.RelativeLink;
var result = client.Post(ConfigurationManager.AppSettings["FacebookPageID"].ToString() + "/feed", parameters);
Please read the docs at
https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed#publish
It's clear that you can't use an App Access Token for posting to a Page, because a Post always needs to be related to a profile.
A user access token with publish_actions permission can be used to publish new posts on behalf of that person. Posts will appear in the voice of the user.
A page access token with publish_pages permission can be used to publish new posts on behalf of that page. Posts will appear in the voice of the page.

Can I use Firebase simple login to access Twitter API?

It's easy to get the simple login working with Twitter, and that's a big bonus, but I was wondering whether it's possible to then take those authentication credentials and post a tweet, get a list of people they're following, generally use the full Twitter 1.1 API. I.e. can I get hold of the access token key and secret?
Thanks,
Dave.
The Firebase Simple Login JavaScript client now returns both the Twitter access token and access token secret in the response payload from Twitter authentication.
You can access each of these via the user object, under the attributes accessToken and accessTokenSecret as shown below:
var firebaseRef = new Firebase('https://<MY-FIREBASE-NAME>.firebaseIO.com');
var authClient = new FirebaseAuthClient(firebaseRef, function(error, user) {
if (user) {
var accessToken = user.accessToken,
accessTokenSecret = user.accessTokenSecret;
}
});
...
// Sample jQuery click event.
$myButton.on('click', function(event) {
authClient.login('twitter');
});

Get Google analytics data using Oauth token?

Here I am using asp.net web to display Google analytic data. I am successfully able to get access token using oauth2.0. Using access token I am also get account information.
Here I want to get Google analytic data using access token. Please share link with me to get data using access token.
I have seen following code
http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/Analytics_DataFeed_Sample/dataFeed.cs
But don't want to use it because here I have to pass user name and password:
private const String CLIENT_USERNAME = "INSERT_LOGIN_EMAIL_HERE";
private const String CLIENT_PASS = "INSERT_PASSWORD_HERE";
Let me know any way to get analytic data using access token.
After long work will get success.....
Here is Oauth playground made by Google developer from you can test your data
https://code.google.com/oauthplayground/
I just Oauth 2.0 for retrieve access token information after that I am using following URL for getting analytic information.
https://developers.google.com/analytics/devguides/reporting/core/v2/gdataReferenceDataFeed
you need to pass access token with your URL ie :
https://www.googleapis.com/analytics/v2.4/data?ids=ga:12345&metrics=ga:visitors,ga:bounces&start-date=2012-07-01&end-date=2012-07-25&access_token=ya29.AHES6ZTzNR6n6FVcmY8uar6izjP9UGeHYNO5nUR7yU2bBqM
Best of luck Enjoy coding..
You can try with following code
string ClientId = "CLIENTID"
string ClientSecret = "CLIENTSECRET"
var Client = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret);
var Auth = new OAuth2Authenticator<NativeApplicationClient>(Client, Authenticate);
var Service = new AnalyticsService(Auth);
var Request = Service.Data.Ga.Get("profileID", StartDate, EndDate, "Matrix");
Request.MaxResults = 1000;
Request.Dimensions = "Dimensions";
var Result = Request.Fetch();

Resources