namespace ASC.FederatedLogin.LoginProviders; [Scope] public class FacebookLoginProvider : BaseLoginProvider { public override string AccessTokenUrl => "https://graph.facebook.com/v2.7/oauth/access_token"; public override string RedirectUri => this["facebookRedirectUrl"]; public override string ClientID => this["facebookClientId"]; public override string ClientSecret => this["facebookClientSecret"]; public override string CodeUrl => "https://www.facebook.com/v2.7/dialog/oauth/"; public override string Scopes => "email,public_profile"; private const string FacebookProfileUrl = "https://graph.facebook.com/v2.7/me?fields=email,id,birthday,link,first_name,last_name,gender,timezone,locale"; public FacebookLoginProvider() { } public FacebookLoginProvider( OAuth20TokenHelper oAuth20TokenHelper, TenantManager tenantManager, CoreBaseSettings coreBaseSettings, CoreSettings coreSettings, IConfiguration configuration, ICacheNotify cache, ConsumerFactory consumerFactory, Signature signature, InstanceCrypto instanceCrypto, string name, int order, Dictionary props, Dictionary additional = null) : base(oAuth20TokenHelper, tenantManager, coreBaseSettings, coreSettings, configuration, cache, consumerFactory, signature, instanceCrypto, name, order, props, additional) { } public override LoginProfile GetLoginProfile(string accessToken) { if (string.IsNullOrEmpty(accessToken)) { throw new Exception("Login failed"); } return RequestProfile(accessToken); } internal LoginProfile ProfileFromFacebook(string facebookProfile) { var jProfile = JObject.Parse(facebookProfile); if (jProfile == null) { throw new Exception("Failed to correctly process the response"); } var profile = new LoginProfile(Signature, InstanceCrypto) { BirthDay = jProfile.Value("birthday"), Link = jProfile.Value("link"), FirstName = jProfile.Value("first_name"), LastName = jProfile.Value("last_name"), Gender = jProfile.Value("gender"), EMail = jProfile.Value("email"), Id = jProfile.Value("id"), TimeZone = jProfile.Value("timezone"), Locale = jProfile.Value("locale"), Provider = ProviderConstants.Facebook, Avatar = "http://graph.facebook.com/" + jProfile.Value("id") + "/picture?type=large" }; return profile; } private LoginProfile RequestProfile(string accessToken) { var facebookProfile = RequestHelper.PerformRequest(FacebookProfileUrl + "&access_token=" + accessToken); var loginProfile = ProfileFromFacebook(facebookProfile); return loginProfile; } }