// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net.Http; using Microsoft.AspNet.Http; using Microsoft.AspNet.Security.OAuth; using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Security.Facebook { /// /// Contains information about the login session as well as the user . /// public class FacebookAuthenticatedContext : OAuthAuthenticatedContext { /// /// Initializes a new . /// /// The HTTP environment. /// The JSON-serialized user. /// The Facebook Access token. public FacebookAuthenticatedContext(HttpContext context, OAuthAuthenticationOptions options, JObject user, TokenResponse tokens) : base(context, options, user, tokens) { Id = TryGetValue(user, "id"); Name = TryGetValue(user, "name"); Link = TryGetValue(user, "link"); UserName = TryGetValue(user, "username"); Email = TryGetValue(user, "email"); } /// /// Gets the Facebook user ID. /// public string Id { get; private set; } /// /// Gets the user's name. /// public string Name { get; private set; } /// /// Gets the user's link. /// public string Link { get; private set; } /// /// Gets the Facebook username. /// public string UserName { get; private set; } /// /// Gets the Facebook email. /// public string Email { get; private set; } private static string TryGetValue(JObject user, string propertyName) { JToken value; return user.TryGetValue(propertyName, out value) ? value.ToString() : null; } } }