Files
OwinOAuthProviders/src/Owin.Security.Providers.Box/Provider/BoxAuthenticatedContext.cs
denis32000 ed5615cd9f Added providers for Box and Baidu (#179)
* Added project with provider for Box cloud service
* Added Baidu provider
2016-10-06 15:49:04 -04:00

78 lines
2.5 KiB
C#

// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Security.Claims;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Provider;
using Newtonsoft.Json.Linq;
namespace Owin.Security.Providers.Box
{
/// <summary>
/// Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.
/// </summary>
public class BoxAuthenticatedContext : BaseContext
{
/// <summary>
/// Initializes a <see cref="BoxAuthenticatedContext"/>
/// </summary>
/// <param name="context">The OWIN environment</param>
/// <param name="user">The JSON-serialized user</param>
/// <param name="accessToken">Box Access token</param>
public BoxAuthenticatedContext(IOwinContext context, JObject user, string accessToken)
: base(context)
{
AccessToken = accessToken;
User = user;
Id = TryGetValue(user, "id");
Name = TryGetValue(user, "name");
Login = TryGetValue(user, "login");
}
/// <summary>
/// Gets the JSON-serialized user
/// </summary>
/// <remarks>
/// Contains the Box user obtained from the endpoint https://api.box.com/2.0/users/me
/// </remarks>
public JObject User { get; private set; }
/// <summary>
/// Gets the Box OAuth access token
/// </summary>
public string AccessToken { get; private set; }
/// <summary>
/// Gets the Box user ID
/// </summary>
public string Id { get; private set; }
/// <summary>
/// The name of the user
/// </summary>
public string Name { get; private set; }
/// <summary>
/// The login of the user
/// </summary>
public string Login { get; private set; }
/// <summary>
/// Gets the <see cref="ClaimsIdentity"/> representing the user
/// </summary>
public ClaimsIdentity Identity { get; set; }
/// <summary>
/// Gets or sets a property bag for common authentication properties
/// </summary>
public AuthenticationProperties Properties { get; set; }
private static string TryGetValue(JObject user, string propertyName)
{
JToken value;
return user.TryGetValue(propertyName, out value) ? value.ToString() : null;
}
}
}