Normalized indentation

This commit is contained in:
ByteBlast
2015-03-13 17:45:54 +00:00
parent ad8f048125
commit 2b51c3fd2e
9 changed files with 473 additions and 473 deletions

View File

@@ -1,7 +1,7 @@
namespace Owin.Security.Providers.EVEOnline
{
internal static class Constants
{
internal const string DefaultAuthenticationType = "EVEOnline";
}
internal static class Constants
{
internal const string DefaultAuthenticationType = "EVEOnline";
}
}

View File

@@ -2,26 +2,26 @@
namespace Owin.Security.Providers.EVEOnline
{
public static class EVEOnlineAuthenticationExtensions
{
public static IAppBuilder UseEVEOnlineAuthentication(this IAppBuilder app, EVEOnlineAuthenticationOptions options)
{
if (app == null)
throw new ArgumentException("app");
if (options == null)
throw new ArgumentException("options");
public static class EVEOnlineAuthenticationExtensions
{
public static IAppBuilder UseEVEOnlineAuthentication(this IAppBuilder app, EVEOnlineAuthenticationOptions options)
{
if (app == null)
throw new ArgumentException("app");
if (options == null)
throw new ArgumentException("options");
app.Use(typeof(EVEOnlineAuthenticationMiddleware), app, options);
app.Use(typeof(EVEOnlineAuthenticationMiddleware), app, options);
return app;
}
public static IAppBuilder UseEVEOnlineAuthentication(this IAppBuilder app, string clientId, string clientSecret)
{
return app.UseEVEOnlineAuthentication(new EVEOnlineAuthenticationOptions
{
ClientId = clientId,
ClientSecret = clientSecret
});
}
}
return app;
}
public static IAppBuilder UseEVEOnlineAuthentication(this IAppBuilder app, string clientId, string clientSecret)
{
return app.UseEVEOnlineAuthentication(new EVEOnlineAuthenticationOptions
{
ClientId = clientId,
ClientSecret = clientSecret
});
}
}
}

View File

@@ -12,24 +12,24 @@ using Newtonsoft.Json.Linq;
namespace Owin.Security.Providers.EVEOnline
{
public class EVEOnlineAuthenticationHandler : AuthenticationHandler<EVEOnlineAuthenticationOptions>
{
public class EVEOnlineAuthenticationHandler : AuthenticationHandler<EVEOnlineAuthenticationOptions>
{
private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
private string _tokenEndpoint,
_characterIdEndpoint,
private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
private string _tokenEndpoint,
_characterIdEndpoint,
_oauthAuthEndpoint,
_serverHost;
private readonly string _serverScheme = "https://";
private readonly ILogger _logger;
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
private readonly HttpClient _httpClient;
public EVEOnlineAuthenticationHandler(HttpClient httpClient, ILogger logger)
{
_httpClient = httpClient;
_logger = logger;
}
public EVEOnlineAuthenticationHandler(HttpClient httpClient, ILogger logger)
{
_httpClient = httpClient;
_logger = logger;
}
protected override System.Threading.Tasks.Task InitializeCoreAsync()
{
@@ -51,48 +51,48 @@ namespace Owin.Security.Providers.EVEOnline
});
}
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
{
AuthenticationProperties properties = null;
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
{
AuthenticationProperties properties = null;
try
{
string code = null;
string state = null;
try
{
string code = null;
string state = null;
var query = Request.Query;
var values = query.GetValues("code");
if (values != null && values.Count == 1)
{
code = values[0];
}
values = query.GetValues("state");
if (values != null && values.Count == 1)
{
state = values[0];
}
var query = Request.Query;
var values = query.GetValues("code");
if (values != null && values.Count == 1)
{
code = values[0];
}
values = query.GetValues("state");
if (values != null && values.Count == 1)
{
state = values[0];
}
properties = Options.StateDataFormat.Unprotect(state);
if (properties == null)
{
return null;
}
properties = Options.StateDataFormat.Unprotect(state);
if (properties == null)
{
return null;
}
// OAuth2 10.12 CSRF
if (!ValidateCorrelationId(properties, _logger))
{
return new AuthenticationTicket(null, properties);
}
// OAuth2 10.12 CSRF
if (!ValidateCorrelationId(properties, _logger))
{
return new AuthenticationTicket(null, properties);
}
// Check for error
if (Request.Query.Get("error") != null)
return new AuthenticationTicket(null, properties);
// Check for error
if (Request.Query.Get("error") != null)
return new AuthenticationTicket(null, properties);
var requestPrefix = Request.Scheme + "://" + Request.Host;
var redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath;
var requestPrefix = Request.Scheme + "://" + Request.Host;
var redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath;
// Build up the body for the token request
var body = new List<KeyValuePair<string, string>>
// Build up the body for the token request
var body = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("grant_type", "authorization_code"),
new KeyValuePair<string, string>("code", code),
@@ -101,184 +101,184 @@ namespace Owin.Security.Providers.EVEOnline
new KeyValuePair<string, string>("client_secret", Options.ClientSecret)
};
// Request the token
var tokenResponse = await _httpClient.PostAsync(_tokenEndpoint, new FormUrlEncodedContent(body));
tokenResponse.EnsureSuccessStatusCode();
var text = await tokenResponse.Content.ReadAsStringAsync();
// Request the token
var tokenResponse = await _httpClient.PostAsync(_tokenEndpoint, new FormUrlEncodedContent(body));
tokenResponse.EnsureSuccessStatusCode();
var text = await tokenResponse.Content.ReadAsStringAsync();
// Deserializes the token response
var response = JsonConvert.DeserializeObject<dynamic>(text);
var accessToken = (string)response.access_token;
// Deserializes the token response
var response = JsonConvert.DeserializeObject<dynamic>(text);
var accessToken = (string)response.access_token;
var refreshToken = string.Empty;
if (response.refresh_token != null)
refreshToken = (string)response.refresh_token;
var expires = (string)response.expires_in;
var expires = (string)response.expires_in;
// Get character data
var graphRequest = new HttpRequestMessage()
// Get character data
var graphRequest = new HttpRequestMessage()
{
Method = HttpMethod.Get,
Method = HttpMethod.Get,
RequestUri = new Uri(_characterIdEndpoint)
};
graphRequest.Headers.Add("Authorization", "Bearer " + accessToken);
graphRequest.Headers.Add("Host", _serverHost);
graphRequest.Headers.UserAgent.ParseAdd("Microsoft Owin EVEOnline middleware");
var graphResponse = await _httpClient.SendAsync(graphRequest);
graphResponse.EnsureSuccessStatusCode();
text = await graphResponse.Content.ReadAsStringAsync();
var characterId = JObject.Parse(text);
var graphResponse = await _httpClient.SendAsync(graphRequest);
graphResponse.EnsureSuccessStatusCode();
text = await graphResponse.Content.ReadAsStringAsync();
var characterId = JObject.Parse(text);
var context = new EVEOnlineAuthenticatedContext(Context, characterId, accessToken, refreshToken, expires)
{
Identity = new ClaimsIdentity(
Options.AuthenticationType,
ClaimsIdentity.DefaultNameClaimType,
ClaimsIdentity.DefaultRoleClaimType)
};
{
Identity = new ClaimsIdentity(
Options.AuthenticationType,
ClaimsIdentity.DefaultNameClaimType,
ClaimsIdentity.DefaultRoleClaimType)
};
if (!string.IsNullOrEmpty(context.CharacterId))
{
context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.CharacterId, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.CharacterName))
{
context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.CharacterName, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.CharacterId))
{
context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.CharacterId, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.CharacterName))
{
context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.CharacterName, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.CharacterOwnerHash))
{
context.Identity.AddClaim(new Claim("urn:eveonline:character_owner_hash", context.CharacterOwnerHash, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.AccessToken))
{
context.Identity.AddClaim(new Claim("urn:eveonline:access_token", context.AccessToken, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.AccessToken))
{
context.Identity.AddClaim(new Claim("urn:eveonline:access_token", context.AccessToken, XmlSchemaString, Options.AuthenticationType));
}
if (!string.IsNullOrEmpty(context.RefreshToken))
{
context.Identity.AddClaim(new Claim("urn:eveonline:refresh_token", context.RefreshToken, XmlSchemaString, Options.AuthenticationType));
}
context.Properties = properties;
context.Properties = properties;
await Options.Provider.Authenticated(context);
await Options.Provider.Authenticated(context);
return new AuthenticationTicket(context.Identity, context.Properties);
return new AuthenticationTicket(context.Identity, context.Properties);
}
catch (Exception ex)
{
_logger.WriteError(ex.Message);
}
return new AuthenticationTicket(null, properties);
}
}
catch (Exception ex)
{
_logger.WriteError(ex.Message);
}
return new AuthenticationTicket(null, properties);
}
protected override Task ApplyResponseChallengeAsync()
{
if (Response.StatusCode != 401)
{
return Task.FromResult<object>(null);
}
protected override Task ApplyResponseChallengeAsync()
{
if (Response.StatusCode != 401)
{
return Task.FromResult<object>(null);
}
var challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);
var challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);
if (challenge != null)
{
var baseUri =
Request.Scheme +
Uri.SchemeDelimiter +
Request.Host +
Request.PathBase;
if (challenge != null)
{
var baseUri =
Request.Scheme +
Uri.SchemeDelimiter +
Request.Host +
Request.PathBase;
var currentUri =
baseUri +
Request.Path +
Request.QueryString;
var currentUri =
baseUri +
Request.Path +
Request.QueryString;
var redirectUri =
baseUri +
Options.CallbackPath;
var redirectUri =
baseUri +
Options.CallbackPath;
var properties = challenge.Properties;
if (string.IsNullOrEmpty(properties.RedirectUri))
{
properties.RedirectUri = currentUri;
}
var properties = challenge.Properties;
if (string.IsNullOrEmpty(properties.RedirectUri))
{
properties.RedirectUri = currentUri;
}
// OAuth2 10.12 CSRF
GenerateCorrelationId(properties);
// OAuth2 10.12 CSRF
GenerateCorrelationId(properties);
// comma separated
var scope = string.Join(" ", Options.Scope);
// comma separated
var scope = string.Join(" ", Options.Scope);
var state = Options.StateDataFormat.Protect(properties);
var state = Options.StateDataFormat.Protect(properties);
var authorizationEndpoint =
_oauthAuthEndpoint +
"?response_type=code" +
"&client_id=" + Uri.EscapeDataString(Options.ClientId) +
"&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
"&scope=" + Uri.EscapeDataString(scope) +
"&state=" + Uri.EscapeDataString(state);
var authorizationEndpoint =
_oauthAuthEndpoint +
"?response_type=code" +
"&client_id=" + Uri.EscapeDataString(Options.ClientId) +
"&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
"&scope=" + Uri.EscapeDataString(scope) +
"&state=" + Uri.EscapeDataString(state);
Response.Redirect(authorizationEndpoint);
}
Response.Redirect(authorizationEndpoint);
}
return Task.FromResult<object>(null);
}
return Task.FromResult<object>(null);
}
public override async Task<bool> InvokeAsync()
{
return await InvokeReplyPathAsync();
}
public override async Task<bool> InvokeAsync()
{
return await InvokeReplyPathAsync();
}
private async Task<bool> InvokeReplyPathAsync()
{
if (Options.CallbackPath.HasValue && Options.CallbackPath == Request.Path)
{
// TODO: error responses
private async Task<bool> InvokeReplyPathAsync()
{
if (Options.CallbackPath.HasValue && Options.CallbackPath == Request.Path)
{
// TODO: error responses
var ticket = await AuthenticateAsync();
if (ticket == null)
{
_logger.WriteWarning("Invalid return state, unable to redirect.");
Response.StatusCode = 500;
return true;
}
var ticket = await AuthenticateAsync();
if (ticket == null)
{
_logger.WriteWarning("Invalid return state, unable to redirect.");
Response.StatusCode = 500;
return true;
}
var context = new EVEOnlineReturnEndpointContext(Context, ticket)
{
SignInAsAuthenticationType = Options.SignInAsAuthenticationType,
RedirectUri = ticket.Properties.RedirectUri
};
var context = new EVEOnlineReturnEndpointContext(Context, ticket)
{
SignInAsAuthenticationType = Options.SignInAsAuthenticationType,
RedirectUri = ticket.Properties.RedirectUri
};
await Options.Provider.ReturnEndpoint(context);
await Options.Provider.ReturnEndpoint(context);
if (context.SignInAsAuthenticationType != null &&
context.Identity != null)
{
ClaimsIdentity grantIdentity = context.Identity;
if (!string.Equals(grantIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal))
{
grantIdentity = new ClaimsIdentity(grantIdentity.Claims, context.SignInAsAuthenticationType, grantIdentity.NameClaimType, grantIdentity.RoleClaimType);
}
Context.Authentication.SignIn(context.Properties, grantIdentity);
}
if (context.SignInAsAuthenticationType != null &&
context.Identity != null)
{
ClaimsIdentity grantIdentity = context.Identity;
if (!string.Equals(grantIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal))
{
grantIdentity = new ClaimsIdentity(grantIdentity.Claims, context.SignInAsAuthenticationType, grantIdentity.NameClaimType, grantIdentity.RoleClaimType);
}
Context.Authentication.SignIn(context.Properties, grantIdentity);
}
if (!context.IsRequestCompleted && context.RedirectUri != null)
{
string redirectUri = context.RedirectUri;
if (context.Identity == null)
{
// add a redirect hint that sign-in failed in some way
redirectUri = WebUtilities.AddQueryString(redirectUri, "error", "access_denied");
}
Response.Redirect(redirectUri);
context.RequestCompleted();
}
if (!context.IsRequestCompleted && context.RedirectUri != null)
{
string redirectUri = context.RedirectUri;
if (context.Identity == null)
{
// add a redirect hint that sign-in failed in some way
redirectUri = WebUtilities.AddQueryString(redirectUri, "error", "access_denied");
}
Response.Redirect(redirectUri);
context.RequestCompleted();
}
return context.IsRequestCompleted;
}
return false;
}
}
return context.IsRequestCompleted;
}
return false;
}
}
}

View File

@@ -11,74 +11,74 @@ using Owin.Security.Providers.Properties;
namespace Owin.Security.Providers.EVEOnline
{
public class EVEOnlineAuthenticationMiddleware : AuthenticationMiddleware<EVEOnlineAuthenticationOptions>
{
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
public class EVEOnlineAuthenticationMiddleware : AuthenticationMiddleware<EVEOnlineAuthenticationOptions>
{
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
public EVEOnlineAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, EVEOnlineAuthenticationOptions options)
: base(next, options)
{
if (String.IsNullOrWhiteSpace(Options.ClientId))
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
Resources.Exception_OptionMustBeProvided, "ClientId"));
if (String.IsNullOrWhiteSpace(Options.ClientSecret))
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
Resources.Exception_OptionMustBeProvided, "ClientSecret"));
public EVEOnlineAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, EVEOnlineAuthenticationOptions options)
: base(next, options)
{
if (String.IsNullOrWhiteSpace(Options.ClientId))
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
Resources.Exception_OptionMustBeProvided, "ClientId"));
if (String.IsNullOrWhiteSpace(Options.ClientSecret))
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
Resources.Exception_OptionMustBeProvided, "ClientSecret"));
_logger = app.CreateLogger<EVEOnlineAuthenticationMiddleware>();
_logger = app.CreateLogger<EVEOnlineAuthenticationMiddleware>();
if (Options.Provider == null)
Options.Provider = new EVEOnlineAuthenticationProvider();
if (Options.Provider == null)
Options.Provider = new EVEOnlineAuthenticationProvider();
if (Options.StateDataFormat == null)
{
var dataProtector = app.CreateDataProtector(
typeof(EVEOnlineAuthenticationMiddleware).FullName,
Options.AuthenticationType, "v1");
Options.StateDataFormat = new PropertiesDataFormat(dataProtector);
}
if (Options.StateDataFormat == null)
{
var dataProtector = app.CreateDataProtector(
typeof(EVEOnlineAuthenticationMiddleware).FullName,
Options.AuthenticationType, "v1");
Options.StateDataFormat = new PropertiesDataFormat(dataProtector);
}
if (String.IsNullOrEmpty(Options.SignInAsAuthenticationType))
Options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType();
if (String.IsNullOrEmpty(Options.SignInAsAuthenticationType))
Options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType();
_httpClient = new HttpClient(ResolveHttpMessageHandler(Options))
{
Timeout = Options.BackchannelTimeout,
MaxResponseContentBufferSize = 1024 * 1024 * 10
};
}
_httpClient = new HttpClient(ResolveHttpMessageHandler(Options))
{
Timeout = Options.BackchannelTimeout,
MaxResponseContentBufferSize = 1024 * 1024 * 10
};
}
/// <summary>
/// Provides the <see cref="T:Microsoft.Owin.Security.Infrastructure.AuthenticationHandler" /> object for processing
/// authentication-related requests.
/// </summary>
/// <returns>
/// An <see cref="T:Microsoft.Owin.Security.Infrastructure.AuthenticationHandler" /> configured with the
/// <see cref="T:Owin.Security.Providers.EVEOnline.EVEOnlineAuthenticationOptions" /> supplied to the constructor.
/// </returns>
protected override AuthenticationHandler<EVEOnlineAuthenticationOptions> CreateHandler()
{
return new EVEOnlineAuthenticationHandler(_httpClient, _logger);
}
/// <summary>
/// Provides the <see cref="T:Microsoft.Owin.Security.Infrastructure.AuthenticationHandler" /> object for processing
/// authentication-related requests.
/// </summary>
/// <returns>
/// An <see cref="T:Microsoft.Owin.Security.Infrastructure.AuthenticationHandler" /> configured with the
/// <see cref="T:Owin.Security.Providers.EVEOnline.EVEOnlineAuthenticationOptions" /> supplied to the constructor.
/// </returns>
protected override AuthenticationHandler<EVEOnlineAuthenticationOptions> CreateHandler()
{
return new EVEOnlineAuthenticationHandler(_httpClient, _logger);
}
private static HttpMessageHandler ResolveHttpMessageHandler(EVEOnlineAuthenticationOptions options)
{
HttpMessageHandler handler = options.BackchannelHttpHandler ?? new WebRequestHandler();
private static HttpMessageHandler ResolveHttpMessageHandler(EVEOnlineAuthenticationOptions options)
{
HttpMessageHandler handler = options.BackchannelHttpHandler ?? 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;
}
// 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;
}
return handler;
}
}
return handler;
}
}
}

View File

@@ -6,110 +6,110 @@ using Microsoft.Owin.Security;
namespace Owin.Security.Providers.EVEOnline
{
public enum Server
{
Tranquility,
public enum Server
{
Tranquility,
Singularity
}
}
public class EVEOnlineAuthenticationOptions : AuthenticationOptions
{
/// <summary>
/// Initializes a new <see cref="EVEOnlineAuthenticationOptions" />.
/// By default the scope is empty, you can add ie. publicData when initializing.
/// </summary>
public EVEOnlineAuthenticationOptions()
: base("EVEOnline")
{
Caption = Constants.DefaultAuthenticationType;
CallbackPath = new PathString("/signin-eveonline");
AuthenticationMode = AuthenticationMode.Passive;
Scope = new List<string>
public class EVEOnlineAuthenticationOptions : AuthenticationOptions
{
/// <summary>
/// Initializes a new <see cref="EVEOnlineAuthenticationOptions" />.
/// By default the scope is empty, you can add ie. publicData when initializing.
/// </summary>
public EVEOnlineAuthenticationOptions()
: base("EVEOnline")
{
Caption = Constants.DefaultAuthenticationType;
CallbackPath = new PathString("/signin-eveonline");
AuthenticationMode = AuthenticationMode.Passive;
Scope = new List<string>
{
};
BackchannelTimeout = TimeSpan.FromSeconds(60);
BackchannelTimeout = TimeSpan.FromSeconds(60);
Server = EVEOnline.Server.Tranquility;
}
}
/// <summary>
/// Gets or sets the a pinned certificate validator to use to validate the endpoints used
/// in back channel communications belong to EVEOnline.
/// </summary>
/// <value>
/// The pinned certificate validator.
/// </value>
/// <remarks>
/// If this property is null then the default certificate checks are performed,
/// validating the subject name and if the signing chain is a trusted party.
/// </remarks>
public ICertificateValidator BackchannelCertificateValidator { get; set; }
/// <summary>
/// Gets or sets the a pinned certificate validator to use to validate the endpoints used
/// in back channel communications belong to EVEOnline.
/// </summary>
/// <value>
/// The pinned certificate validator.
/// </value>
/// <remarks>
/// If this property is null then the default certificate checks are performed,
/// validating the subject name and if the signing chain is a trusted party.
/// </remarks>
public ICertificateValidator BackchannelCertificateValidator { get; set; }
/// <summary>
/// The HttpMessageHandler used to communicate with EVEOnline.
/// This cannot be set at the same time as BackchannelCertificateValidator unless the value
/// can be downcast to a WebRequestHandler.
/// </summary>
public HttpMessageHandler BackchannelHttpHandler { get; set; }
/// <summary>
/// The HttpMessageHandler used to communicate with EVEOnline.
/// This cannot be set at the same time as BackchannelCertificateValidator unless the value
/// can be downcast to a WebRequestHandler.
/// </summary>
public HttpMessageHandler BackchannelHttpHandler { get; set; }
/// <summary>
/// Gets or sets timeout value in milliseconds for back channel communications with EVEOnline.
/// </summary>
/// <value>
/// The back channel timeout in milliseconds.
/// </value>
public TimeSpan BackchannelTimeout { get; set; }
/// <summary>
/// Gets or sets timeout value in milliseconds for back channel communications with EVEOnline.
/// </summary>
/// <value>
/// The back channel timeout in milliseconds.
/// </value>
public TimeSpan BackchannelTimeout { get; set; }
/// <summary>
/// The request path within the application's base path where the user-agent will be returned.
/// The middleware will process this request when it arrives.
/// Default value is "/signin-eveonline".
/// </summary>
public PathString CallbackPath { get; set; }
/// <summary>
/// The request path within the application's base path where the user-agent will be returned.
/// The middleware will process this request when it arrives.
/// Default value is "/signin-eveonline".
/// </summary>
public PathString CallbackPath { get; set; }
/// <summary>
/// Get or sets the text that the user can display on a sign in user interface.
/// </summary>
public string Caption
{
get { return Description.Caption; }
set { Description.Caption = value; }
}
/// <summary>
/// Get or sets the text that the user can display on a sign in user interface.
/// </summary>
public string Caption
{
get { return Description.Caption; }
set { Description.Caption = value; }
}
/// <summary>
/// Gets or sets EVEOnline supplied Client Id
/// </summary>
public string ClientId { get; set; }
/// <summary>
/// Gets or sets EVEOnline supplied Client Id
/// </summary>
public string ClientId { get; set; }
/// <summary>
/// Gets or sets EVEOnline supplied Client Secret
/// </summary>
public string ClientSecret { get; set; }
/// <summary>
/// Gets or sets EVEOnline supplied Client Secret
/// </summary>
public string ClientSecret { get; set; }
/// <summary>
/// Gets or sets the EVEOnline Server to authenticate against.
/// </summary>
public Server Server { get; set; }
/// <summary>
/// Gets or sets the EVEOnline Server to authenticate against.
/// </summary>
public Server Server { get; set; }
/// <summary>
/// Gets or sets the <see cref="IEVEOnlineAuthenticationProvider" /> used in the authentication events
/// </summary>
public IEVEOnlineAuthenticationProvider Provider { get; set; }
/// <summary>
/// Gets or sets the <see cref="IEVEOnlineAuthenticationProvider" /> used in the authentication events
/// </summary>
public IEVEOnlineAuthenticationProvider Provider { get; set; }
/// <summary>
/// A list of permissions to request.
/// </summary>
public IList<string> Scope { get; private set; }
/// <summary>
/// A list of permissions to request.
/// </summary>
public IList<string> Scope { get; private set; }
/// <summary>
/// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user
/// <see cref="System.Security.Claims.ClaimsIdentity" />.
/// </summary>
public string SignInAsAuthenticationType { get; set; }
/// <summary>
/// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user
/// <see cref="System.Security.Claims.ClaimsIdentity" />.
/// </summary>
public string SignInAsAuthenticationType { get; set; }
/// <summary>
/// Gets or sets the type used to secure data handled by the middleware.
/// </summary>
public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }
/// <summary>
/// Gets or sets the type used to secure data handled by the middleware.
/// </summary>
public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }
}
}
}

View File

@@ -10,59 +10,59 @@ using Newtonsoft.Json.Linq;
namespace Owin.Security.Providers.EVEOnline
{
/// <summary>
/// Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.
/// </summary>
public class EVEOnlineAuthenticatedContext : BaseContext
{
/// <summary>
/// Initializes a <see cref="EVEOnlineAuthenticatedContext"/>
/// </summary>
/// <param name="context">The OWIN environment</param>
/// <param name="characterData">The JSON-serialized userId</param>
/// <summary>
/// Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.
/// </summary>
public class EVEOnlineAuthenticatedContext : BaseContext
{
/// <summary>
/// Initializes a <see cref="EVEOnlineAuthenticatedContext"/>
/// </summary>
/// <param name="context">The OWIN environment</param>
/// <param name="characterData">The JSON-serialized userId</param>
///
/// <param name="accessToken">EVEOnline Access token</param>
/// <param name="expires">Seconds until expiration</param>
/// <param name="accessToken">EVEOnline Access token</param>
/// <param name="expires">Seconds until expiration</param>
public EVEOnlineAuthenticatedContext(IOwinContext context, JObject characterData, string accessToken, string refreshToken, string expires)
: base(context)
{
JsonCharacterId = characterData;
AccessToken = accessToken;
: base(context)
{
JsonCharacterId = characterData;
AccessToken = accessToken;
RefreshToken = refreshToken;
int expiresValue;
if (Int32.TryParse(expires, NumberStyles.Integer, CultureInfo.InvariantCulture, out expiresValue))
{
ExpiresIn = TimeSpan.FromSeconds(expiresValue);
}
int expiresValue;
if (Int32.TryParse(expires, NumberStyles.Integer, CultureInfo.InvariantCulture, out expiresValue))
{
ExpiresIn = TimeSpan.FromSeconds(expiresValue);
}
CharacterId = TryGetValue(characterData, "CharacterID");
CharacterName = TryGetValue(characterData, "CharacterName");
CharacterOwnerHash = TryGetValue(characterData, "CharacterOwnerHash");
}
}
/// <summary>
/// Gets the JSON-serialized user ID
/// </summary>
/// <remarks>
/// Contains the EVEOnline user ID
/// </remarks>
public JObject JsonCharacterId { get; private set; }
/// <summary>
/// Gets the JSON-serialized user ID
/// </summary>
/// <remarks>
/// Contains the EVEOnline user ID
/// </remarks>
public JObject JsonCharacterId { get; private set; }
/// <summary>
/// Gets EVEOnline OAuth access token
/// </summary>
public string AccessToken { get; private set; }
/// <summary>
/// Gets EVEOnline OAuth access token
/// </summary>
public string AccessToken { get; private set; }
/// <summary>
/// Gets EVEOnline OAuth refresh token
/// </summary>
public string RefreshToken { get; private set; }
/// <summary>
/// Gets EVEOnline access token expiration time
/// </summary>
public TimeSpan? ExpiresIn { get; set; }
/// <summary>
/// Gets EVEOnline access token expiration time
/// </summary>
public TimeSpan? ExpiresIn { get; set; }
/// <summary>
/// Gets EVEOnline character owner hash. It changes only if character is transfered
@@ -70,30 +70,30 @@ namespace Owin.Security.Providers.EVEOnline
/// </summary>
public string CharacterOwnerHash { get; private set; }
/// <summary>
/// Gets EVEOnline character ID
/// </summary>
public string CharacterId { get; private set; }
/// <summary>
/// Gets EVEOnline character ID
/// </summary>
public string CharacterId { get; private set; }
/// <summary>
/// Gets the EVEOnline character name
/// </summary>
public string CharacterName { get; private set; }
/// <summary>
/// Gets the <see cref="ClaimsIdentity"/> representing the user
/// </summary>
public ClaimsIdentity Identity { get; 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; }
/// <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;
}
}
private static string TryGetValue(JObject user, string propertyName)
{
JToken value;
return user.TryGetValue(propertyName, out value) ? value.ToString() : null;
}
}
}

View File

@@ -4,48 +4,48 @@ using System.Threading.Tasks;
namespace Owin.Security.Providers.EVEOnline
{
/// <summary>
/// Default <see cref="IEVEOnlineAuthenticationProvider"/> implementation.
/// </summary>
public class EVEOnlineAuthenticationProvider : IEVEOnlineAuthenticationProvider
{
/// <summary>
/// Initializes a <see cref="EVEOnlineAuthenticationProvider"/>
/// </summary>
/// <summary>
/// Default <see cref="IEVEOnlineAuthenticationProvider"/> implementation.
/// </summary>
public class EVEOnlineAuthenticationProvider : IEVEOnlineAuthenticationProvider
{
/// <summary>
/// Initializes a <see cref="EVEOnlineAuthenticationProvider"/>
/// </summary>
public EVEOnlineAuthenticationProvider()
{
OnAuthenticated = context => Task.FromResult<object>(null);
OnReturnEndpoint = context => Task.FromResult<object>(null);
}
{
OnAuthenticated = context => Task.FromResult<object>(null);
OnReturnEndpoint = context => Task.FromResult<object>(null);
}
/// <summary>
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
/// </summary>
/// <summary>
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
/// </summary>
public Func<EVEOnlineAuthenticatedContext, Task> OnAuthenticated { get; set; }
/// <summary>
/// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked.
/// </summary>
/// <summary>
/// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked.
/// </summary>
public Func<EVEOnlineReturnEndpointContext, Task> OnReturnEndpoint { get; set; }
/// <summary>
/// Invoked whenever Battle.net successfully authenticates a user
/// </summary>
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
/// <summary>
/// Invoked whenever Battle.net successfully authenticates a user
/// </summary>
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
public Task Authenticated(EVEOnlineAuthenticatedContext context)
{
return OnAuthenticated(context);
}
{
return OnAuthenticated(context);
}
/// <summary>
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
/// </summary>
/// <param name="context"></param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
public Task ReturnEndpoint(EVEOnlineReturnEndpointContext context)
{
return OnReturnEndpoint(context);
}
}
/// <summary>
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
/// </summary>
/// <param name="context"></param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
public Task ReturnEndpoint(EVEOnlineReturnEndpointContext context)
{
return OnReturnEndpoint(context);
}
}
}

View File

@@ -6,21 +6,21 @@ using Microsoft.Owin.Security.Provider;
namespace Owin.Security.Providers.EVEOnline
{
/// <summary>
/// Provides context information to middleware providers.
/// </summary>
public class EVEOnlineReturnEndpointContext : ReturnEndpointContext
{
/// <summary>
///
/// </summary>
/// <param name="context">OWIN environment</param>
/// <param name="ticket">The authentication ticket</param>
/// <summary>
/// Provides context information to middleware providers.
/// </summary>
public class EVEOnlineReturnEndpointContext : ReturnEndpointContext
{
/// <summary>
///
/// </summary>
/// <param name="context">OWIN environment</param>
/// <param name="ticket">The authentication ticket</param>
public EVEOnlineReturnEndpointContext(
IOwinContext context,
AuthenticationTicket ticket)
: base(context, ticket)
{
}
}
IOwinContext context,
AuthenticationTicket ticket)
: base(context, ticket)
{
}
}
}

View File

@@ -2,20 +2,20 @@
namespace Owin.Security.Providers.EVEOnline
{
public interface IEVEOnlineAuthenticationProvider
{
/// <summary>
/// Invoked whenever Battle.net succesfully authenticates a user
/// </summary>
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
public interface IEVEOnlineAuthenticationProvider
{
/// <summary>
/// Invoked whenever Battle.net succesfully authenticates a user
/// </summary>
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
Task Authenticated(EVEOnlineAuthenticatedContext context);
/// <summary>
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
/// </summary>
/// <param name="context"></param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
/// <summary>
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
/// </summary>
/// <param name="context"></param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
Task ReturnEndpoint(EVEOnlineReturnEndpointContext context);
}
}
}