/// <summary> /// Initializes a new <see cref="MicrosoftAccountAuthenticatedContext"/>. /// </summary> /// <param name="context">The HTTP environment.</param> /// <param name="user">The JSON-serialized user.</param> /// <param name="tokens">The access token provided by the Microsoft authentication service.</param> public MicrosoftAccountAuthenticatedContext(HttpContext context, OAuthAuthenticationOptions options, [NotNull] JObject user, TokenResponse tokens) : base(context, options, user, tokens) { IDictionary<string, JToken> userAsDictionary = user; JToken userId = User["id"]; if (userId == null) { throw new ArgumentException(Resources.Exception_MissingId, "user"); } Id = userId.ToString(); Name = PropertyValueIfExists("name", userAsDictionary); FirstName = PropertyValueIfExists("first_name", userAsDictionary); LastName = PropertyValueIfExists("last_name", userAsDictionary); if (userAsDictionary.ContainsKey("emails")) { JToken emailsNode = user["emails"]; foreach (var childAsProperty in emailsNode.OfType<JProperty>().Where(childAsProperty => childAsProperty.Name == "preferred")) { Email = childAsProperty.Value.ToString(); } } }
/// <summary> /// Initializes a new <see cref="FacebookAuthenticatedContext"/>. /// </summary> /// <param name="context">The HTTP environment.</param> /// <param name="user">The JSON-serialized user.</param> /// <param name="tokens">The Facebook Access token.</param> 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"); }
/// <summary> /// Initializes a new <see cref="GoogleAuthenticatedContext"/>. /// </summary> /// <param name="context">The HTTP environment.</param> /// <param name="user">The JSON-serialized Google user info.</param> /// <param name="tokens">Google OAuth 2.0 access token, refresh token, etc.</param> public GoogleAuthenticatedContext(HttpContext context, OAuthAuthenticationOptions options, JObject user, TokenResponse tokens) : base(context, options, user, tokens) { Id = TryGetValue(user, "id"); Name = TryGetValue(user, "displayName"); GivenName = TryGetValue(user, "name", "givenName"); FamilyName = TryGetValue(user, "name", "familyName"); Profile = TryGetValue(user, "url"); Email = TryGetFirstValue(user, "emails", "value"); }
private static HttpMessageHandler ResolveHttpMessageHandler(OAuthAuthenticationOptions options) { HttpMessageHandler handler = options.BackchannelHttpHandler ?? #if DNX451 new WebRequestHandler(); // If they provided a validator, apply it or fail. if (options.BackchannelCertificateValidator != null) { // Set the cert validate callback var webRequestHandler = handler as WebRequestHandler; if (webRequestHandler == null) { throw new InvalidOperationException(Resources.Exception_ValidatorHandlerMismatch); } webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate; } #else new WinHttpHandler(); #endif return(handler); }
public RunkeeperAuthenticatedContext(HttpContext context, OAuthAuthenticationOptions options, JObject user, TokenResponse tokens) : base(context, options, user, tokens) { }