I am using OAuthWebSecurity to make my MVC application Facebook login ready. Everything works as expected.
However, the provider only return the Facebook username (email address) back to my client. I like to also receive the Firstname and the Lastname but did not find any example how to do this with OAuthWebSecurity.
Is it possible to extend the Facebook provider without make use of the big Facebook sdk?
Ok, after some more research I find out that it is the easiest way to just use the Facebook SDK and use following code fregment to access this information:
var client = new FacebookClient(result.ExtraData["accesstoken"]);
dynamic me = client.Get("me");
string firstName = me.first_name;
string lastName = me.last_name;
string email = me.email;
string gender = me.gender;
It would be much more complicated to extend the Facebook OAuth provider.
Related
I'm writing a simple application in Xamarin.Forms that allows users the authentication through socials such as Facebook, Google, Instagram, Twitter, etc. I'm using Xamarin.auth to do this. I have a problem with Facebook Login. I used the same code reported in the official guide:
https://components.xamarin.com/gettingstarted/xamarin.auth
But after the application has requested the user for credentials, the response (in the code, t.Result.GetResponseText(), section 3) is a json contains the Facebook user name and surname, and a field called "id". Instead, I need all profile informations of the user, such as age, gender, etc. I suppose that I have to use the id returned for build an http request to a facebook service for retrieve data from the id.
You need to specify in your facebook link the requiered fields.
Example:
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=email,first_name,last_name,gender,picture"), null, eventArgs.Account);
After how I Get the fields
var response = await request.GetResponseAsync();
var obj = JObject.Parse(response.GetResponseText());
var id = obj["id"].ToString().Replace("\"", "");
var name = obj["first_name"].ToString().Replace("\"", "");
var lastName = obj["last_name"].ToString().Replace("\"", "");
var email = obj["email"].ToString().Replace("\"", "");
'm using the Facebook SDK 6.0 for Unity3D.
After my user accept the connection, I want to save his ID, email etc ... on a Parse database, and have the possibility to get some info from this database for this player (for exemple : the list of unlock levels).
How can I do it ?
I know how create an object, but I want to know, after a connection on Facebook, how to save the user and some details on Parse, without using the Parse login (as on the official Parse tutorial).
I can't understand.
Thank you very very much in advance for your help.
Best regards,
AB
You can try saving this information in the local ParseUser Object. Just add custom fields with the necessary information. For more complex solutions you can create a custom parse object to save the information.
https://parse.com/docs/unity_guide#users
var user = new ParseUser()
{
Username = "my name",
Password = "my pass",
Email = "email#example.com"
};
// other fields can be set just like with ParseObject
user["IsUnlocked"] = true;
Task signUpTask = user.SignUpAsync();
and for Facebook there is a special signup method in the ParseFacebookUtils class
https://parse.com/docs/unity_guide#fbusers
Task<ParseUser> logInTask = ParseFacebookUtils.LogInAsync(userId, accessToken, tokenExpiration);
I am using the wonderful Grails Facebook Plugin and things are working alright. The problem comes from the fact that I provide another way to authenticate: forms authentication. If there is already a user in the system with the email address of the Facebook user, I would like to gracefully alert the user of this fact. I don't know how to do that since I am buried inside of a service which gets called from a Filter. Ideally I would like to show an error message on the login page. Is this possible?
Inside my FacebookAuthService:
FacebookUser create(FacebookAuthToken token) {
log.info("Create domain for facebook user $token.uid")
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
String email = fbProfile.getEmail()
String emailMatch = User.findByEmailAddress(email)
if(emailMatch != null)
throw new RuntimeException("username is bad!!")
I want to display this error message to the user instead of the exception trickling all the way through. How can I do this? Thanks!
You can put this message into a flash object:
def grailsWebRequest = WebUtils.retrieveGrailsWebRequest()
def flash = grailsWebRequest.attributes.getFlashScope(request)
flash.error = "username is bad!!!"
return null // Facebook filter will skip authorization at this case
Also, instead of RuntimeException it's better to use instance of AuthenticationException. At this case you can configure Spring Security to redirect to special url after exception. Just put into Config.groovy:
grails.plugins.springsecurity.failureHandler.exceptionMappings = [
'MyException': '/usernameIsBad'
]
I have a minor problem in facebook c# sdk
I just want to get the facebook user id without asking for permissions , just from the signed request. Up to now i have written the code below:
var current = new DefaultFacebookApplication { AppId ="***", AppSecret = "***" };
dynamic signedRequest = FacebookSignedRequest.Parse(current, Request);
var UserId = (string)signedRequest.Data.user.id;
My first question is :is that is possible? Is it possible to get the user id without oauth?
Secondly , if it is possible is the (string)signedRequest.Data.user.id statement correct?;
You cannot get the Facebook user id from the signed_request unless they've authenticated your app. It is a privacy issue.
I'm trying to convert friend pages into fan pages (most businesses have created friend pages by mistake) and am trying to email everyone on a friend list about the move.
I've tried
FQL "SELECT email FROM user WHERE uid=xxxx"
Creating groups (not good for 5000 friend pages)
Restfb: Connection myFriends = facebookClient.fetchConnection("me/friends", User.class) etc;
The FQL and RestFB methods are both returning nada, group email method is just plain messy.
Is this a security feature or can this data ever by returned for my purpose?
Cheers
to access user's private informations like email,posts etc you should have the permission to access those details .for more details visit https://developers.facebook.com/docs/reference/api/permissions/
If you are using restfb (Facebook graph API and old REST API client wriiten in Java), and you want to access all friend list after Oauth authentication, you can use following method to access the friends list and facebook id's,
public List<ArrayList> findFacebookFriendsUsingRest(String facebookAccessToken){
List<ArrayList> myFacebookFriendList= new ArrayList();
final FacebookClient facebookClient;
facebookClient = new DefaultFacebookClient(facebookAccessToken);
User user = facebookClient.fetchObject("me", User.class);
String userName = user.getFirstName();
if (userName == null){
userName = user.getLastName();
}
String userEmail = user.getEmail();
com.restfb.Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);
System.out.println("Count of my friends: " + myFriends.getData().size());
for(User friend: myFriends.getData()){
System.out.println("Friends id and name: "+friend.getId()+" , "+friend.getName());
myFacebookFriendList.add(friend.getName());
}
System.out.println("All Friends : "+myFacebookFriendList);
}
Facebook does not provide user, unless the user authorizes your application to access it. It's on account of security and user privacy, imagine how terrible it would be if everybody could have at her disposal all FB user's email addresses.
Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class ,Parameter.with("fields", "id, name, picture, email"));
You can specify any of the properties listed under
http://developers.facebook.com/docs/reference/api/user
The only thing is that FB does not seam to return the friends email..
I'm using restFb 1.5.3