Trying to determine the best way to allow website members to register/login with Facebook login.
Getting the members to login with Facebook and retrieving an accessToken I can create a link between the member and their facebook account by storing their Facebook Id in the member.
I'm just struggling with how to authenticate the member when they go to login.
So, when a user goes to login via Facebook, I can retrieve the member via:
var client = new FacebookClient(accessToken);
dynamic user = client.Get("me");
var memberService = Services.MemberService;
IEnumerable<IMember> existingMembers = memberService.GetMembersByPropertyValue("facebookUserId", user.id);
But I can't see how I can authenticate the user as the Members.Login method requires both username and password as per what would normally be supplied with a typical login form.
Just to expand on my code, The user is Authenticated via the Facebook JS SDK.
So on my Login View page I have:
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'MY_APP_ID',
xfbml: true,
version: 'v2.5'
});
// Additional initialization code here
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var userAccessToken = response.authResponse.accessToken;
$.post("/umbraco/Surface/BookingAgentSurface/FacebookLogin", { accessToken: userAccessToken });
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
};
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
So once the user is logged in, the Facebook subscribe event posts back to my SurfaceController with the userAccessToken, so my SurfaceController looks something like this:
public ActionResult FacebookLogin()
{
string accessToken = HttpContext.Request["accessToken"];
try
{
var client = new FacebookClient(accessToken);
dynamic user = client.Get("me");
var memberService = Services.MemberService;
IEnumerable<IMember> ExistingMember = memberService.GetMembersByPropertyValue("facebookUserId", user.id);
if (ExistingMember.Any())
{
IMember existingMember = ExistingMember.FirstOrDefault();
System.Web.Security.FormsAuthentication.SetAuthCookie(existingMember.Username, true);
//USER IS LOGGED IN, REDIRECT TO ADMIN SECTION ETC
return Redirect(Constants.AppPaths.BOOKING_AGENT_DASHBOARD);
}
else
{
//USER IS NOT LOGGED IN
return "User not found ";
}
}
catch (Exception e)
{
return e.Message + " " + e.StackTrace;
}
}
Authenticating Member via Facebook login
Trying to determine the best way to allow website members to register/login with Facebook login.
Getting the members to login with Facebook and retrieving an accessToken I can create a link between the member and their facebook account by storing their Facebook Id in the member.
I'm just struggling with how to authenticate the member when they go to login.
So, when a user goes to login via Facebook, I can retrieve the member via:
But I can't see how I can authenticate the user as the Members.Login method requires both username and password as per what would normally be supplied with a typical login form.
I've tried:
With no success
Anyone else who gets stuck on this, you can authenticate a user by simply setting the AutCookie session with:
Just to expand on my code, The user is Authenticated via the Facebook JS SDK.
So on my Login View page I have:
And to render the Login Button:
So once the user is logged in, the Facebook subscribe event posts back to my SurfaceController with the userAccessToken, so my SurfaceController looks something like this:
Which libraries have you used?
Skybrud plus Facebook JS SDK?
My $post is generating error
+1
Good!
Which libraries have you used in above code. where is this "FacebookClient" coming from?
I am also trying to implement external login for "Members" on my site.
Thanks
You can use Facebook .NET SDK or Skybrud social
https://github.com/abjerner/Skybrud.Social
Install UmbracoIdentityMember
Thanks, appreciate quick response.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.