got the server lib
parent
6fe0dad775
commit
dac93a6206
@ -1,118 +0,0 @@
|
|||||||
using GoogleTranslateNET.Misc;
|
|
||||||
|
|
||||||
namespace GoogleTranslateNET
|
|
||||||
{
|
|
||||||
public enum Language
|
|
||||||
{
|
|
||||||
Unknown,
|
|
||||||
Automatic,
|
|
||||||
[StringValue("af")]
|
|
||||||
Afrikaans,
|
|
||||||
[StringValue("sq")]
|
|
||||||
Albanian,
|
|
||||||
[StringValue("ar")]
|
|
||||||
Arabic,
|
|
||||||
[StringValue("be")]
|
|
||||||
Belarusian,
|
|
||||||
[StringValue("bg")]
|
|
||||||
Bulgarian,
|
|
||||||
[StringValue("ca")]
|
|
||||||
Catalan,
|
|
||||||
[StringValue("zh")]
|
|
||||||
ChineseSimplified,
|
|
||||||
[StringValue("zh-TW")]
|
|
||||||
ChineseTraditional,
|
|
||||||
[StringValue("hr")]
|
|
||||||
Croatian,
|
|
||||||
[StringValue("cs")]
|
|
||||||
Czech,
|
|
||||||
[StringValue("da")]
|
|
||||||
Danish,
|
|
||||||
[StringValue("nl")]
|
|
||||||
Dutch,
|
|
||||||
[StringValue("en")]
|
|
||||||
English,
|
|
||||||
[StringValue("eo")]
|
|
||||||
Esperanto,
|
|
||||||
[StringValue("et")]
|
|
||||||
Estonian,
|
|
||||||
[StringValue("tl")]
|
|
||||||
Filipino,
|
|
||||||
[StringValue("fi")]
|
|
||||||
Finnish,
|
|
||||||
[StringValue("fr")]
|
|
||||||
French,
|
|
||||||
[StringValue("gl")]
|
|
||||||
Galician,
|
|
||||||
[StringValue("de")]
|
|
||||||
German,
|
|
||||||
[StringValue("el")]
|
|
||||||
Greek,
|
|
||||||
[StringValue("ht")]
|
|
||||||
HaitianCreole,
|
|
||||||
[StringValue("iw")]
|
|
||||||
Hebrew,
|
|
||||||
[StringValue("hi")]
|
|
||||||
Hindi,
|
|
||||||
[StringValue("hu")]
|
|
||||||
Hungarian,
|
|
||||||
[StringValue("is")]
|
|
||||||
Icelandic,
|
|
||||||
[StringValue("id")]
|
|
||||||
Indonesian,
|
|
||||||
[StringValue("ga")]
|
|
||||||
Irish,
|
|
||||||
[StringValue("it")]
|
|
||||||
Italian,
|
|
||||||
[StringValue("ja")]
|
|
||||||
Japanese,
|
|
||||||
[StringValue("ko")]
|
|
||||||
Korean,
|
|
||||||
[StringValue("lv")]
|
|
||||||
Latvian,
|
|
||||||
[StringValue("lt")]
|
|
||||||
Lithuanian,
|
|
||||||
[StringValue("mk")]
|
|
||||||
Macedonian,
|
|
||||||
[StringValue("ms")]
|
|
||||||
Malay,
|
|
||||||
[StringValue("mt")]
|
|
||||||
Maltese,
|
|
||||||
[StringValue("no")]
|
|
||||||
Norwegian,
|
|
||||||
[StringValue("fa")]
|
|
||||||
Persian,
|
|
||||||
[StringValue("pl")]
|
|
||||||
Polish,
|
|
||||||
[StringValue("pt")]
|
|
||||||
Portuguese,
|
|
||||||
[StringValue("ro")]
|
|
||||||
Romanian,
|
|
||||||
[StringValue("ru")]
|
|
||||||
Russian,
|
|
||||||
[StringValue("sr")]
|
|
||||||
Serbian,
|
|
||||||
[StringValue("sk")]
|
|
||||||
Slovak,
|
|
||||||
[StringValue("sl")]
|
|
||||||
Slovenian,
|
|
||||||
[StringValue("es")]
|
|
||||||
Spanish,
|
|
||||||
[StringValue("sw")]
|
|
||||||
Swahili,
|
|
||||||
[StringValue("sv")]
|
|
||||||
Swedish,
|
|
||||||
[StringValue("th")]
|
|
||||||
Thai,
|
|
||||||
[StringValue("tr")]
|
|
||||||
Turkish,
|
|
||||||
[StringValue("uk")]
|
|
||||||
Ukrainian,
|
|
||||||
[StringValue("vi")]
|
|
||||||
Vietnamese,
|
|
||||||
[StringValue("cy")]
|
|
||||||
Welsh,
|
|
||||||
[StringValue("yi")]
|
|
||||||
Yiddish
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace GoogleTranslateNET.Misc
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// This attribute is used to represent a string value
|
|
||||||
/// for a value in an enum.
|
|
||||||
/// </summary>
|
|
||||||
public class StringValueAttribute : Attribute
|
|
||||||
{
|
|
||||||
public string StringValue { get; private set; }
|
|
||||||
|
|
||||||
public StringValueAttribute(string value)
|
|
||||||
{
|
|
||||||
StringValue = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.Error
|
|
||||||
{
|
|
||||||
public class ErrorData
|
|
||||||
{
|
|
||||||
public string Domain { get; set; }
|
|
||||||
public string Reason { get; set; }
|
|
||||||
public string Message { get; set; }
|
|
||||||
public string LocationType { get; set; }
|
|
||||||
public string Location { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.Error
|
|
||||||
{
|
|
||||||
public class ErrorResponse
|
|
||||||
{
|
|
||||||
public Error Error { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.LanguageDetection
|
|
||||||
{
|
|
||||||
public class LanguageDetection
|
|
||||||
{
|
|
||||||
public string Language { get; set; }
|
|
||||||
public bool IsReliable { get; set; }
|
|
||||||
public float Confidence { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace GoogleTranslateNET.Objects.LanguageDetection
|
|
||||||
{
|
|
||||||
public class LanguageDetectionData
|
|
||||||
{
|
|
||||||
public List<List<LanguageDetection>> Detections { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.LanguageDetection
|
|
||||||
{
|
|
||||||
public class LanguageDetectionResult
|
|
||||||
{
|
|
||||||
public LanguageDetectionData Data { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace GoogleTranslateNET.Objects.SupportedLanguages
|
|
||||||
{
|
|
||||||
public class SupportedLanguageData
|
|
||||||
{
|
|
||||||
public List<TranslationLanaguage> Languages { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.SupportedLanguages
|
|
||||||
{
|
|
||||||
public class SupportedLanguageResult
|
|
||||||
{
|
|
||||||
public SupportedLanguageData Data { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.SupportedLanguages
|
|
||||||
{
|
|
||||||
public class TranslationLanaguage
|
|
||||||
{
|
|
||||||
public string Language { get; set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.Translation
|
|
||||||
{
|
|
||||||
public class TranslateResult
|
|
||||||
{
|
|
||||||
public TranslationData Data { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
namespace GoogleTranslateNET.Objects.Translation
|
|
||||||
{
|
|
||||||
public class Translation
|
|
||||||
{
|
|
||||||
public string TranslatedText { get; set; }
|
|
||||||
public string DetectedSourceLanguage { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace GoogleTranslateNET.Objects.Translation
|
|
||||||
{
|
|
||||||
public class TranslationData
|
|
||||||
{
|
|
||||||
public List<Translation> Translations { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.5-*",
|
|
||||||
"title": "Yavsc Google Translate [DNX]",
|
|
||||||
"description": "Google Translate for DNX",
|
|
||||||
"authors": [
|
|
||||||
"Paul Schneider <paul@pschneider.fr>"
|
|
||||||
],
|
|
||||||
"packOptions": {
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/pazof/yavsc"
|
|
||||||
},
|
|
||||||
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
|
|
||||||
"requireLicenseAcceptance": true,
|
|
||||||
"owners": [
|
|
||||||
"Paul Schneider <paul@pschneider.fr>"
|
|
||||||
],
|
|
||||||
"summary": "CSharp Google Tranlate API",
|
|
||||||
"projectUrl": "http://yavsc.pschneider.fr",
|
|
||||||
"tags": [
|
|
||||||
"Translation"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"tooling": {
|
|
||||||
"defaultNamespace": "Yavsc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"Newtonsoft.Json": "6.0.1-beta1",
|
|
||||||
"Gapi.net45": "1.0.1",
|
|
||||||
"RestSharp": "103.4.0"
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"dnx451": {
|
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.ComponentModel.DataAnnotations": "4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"net46": {
|
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.ComponentModel.DataAnnotations": "4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"net461": {
|
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.ComponentModel.DataAnnotations": "4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"net452": {
|
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.ComponentModel.DataAnnotations": "4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"net451": {
|
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.ComponentModel.DataAnnotations": "4.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
public class AuthenticationTokenCreateContext : BaseContext
|
|
||||||
{
|
|
||||||
private readonly ISecureDataFormat<AuthenticationTicket> _secureDataFormat;
|
|
||||||
|
|
||||||
public AuthenticationTokenCreateContext(HttpContext context, ISecureDataFormat<AuthenticationTicket> secureDataFormat, AuthenticationTicket ticket) : base(context)
|
|
||||||
{
|
|
||||||
if (secureDataFormat == null)
|
|
||||||
throw new ArgumentNullException(nameof(secureDataFormat));
|
|
||||||
|
|
||||||
if (ticket == null)
|
|
||||||
throw new ArgumentNullException(nameof(ticket));
|
|
||||||
|
|
||||||
_secureDataFormat = secureDataFormat;
|
|
||||||
|
|
||||||
Ticket = ticket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Token { get; protected set; }
|
|
||||||
|
|
||||||
public AuthenticationTicket Ticket { get; protected set; }
|
|
||||||
|
|
||||||
public string SerializeTicket()
|
|
||||||
{
|
|
||||||
return _secureDataFormat.Protect(Ticket);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetToken(string tokenValue)
|
|
||||||
{
|
|
||||||
if (tokenValue == null)
|
|
||||||
throw new ArgumentNullException(nameof(tokenValue));
|
|
||||||
|
|
||||||
Token = tokenValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
public class AuthenticationTokenProvider : IAuthenticationTokenProvider
|
|
||||||
{
|
|
||||||
public Action<AuthenticationTokenCreateContext> OnCreate { get; set; }
|
|
||||||
public Func<AuthenticationTokenCreateContext, Task> OnCreateAsync { get; set; }
|
|
||||||
public Action<AuthenticationTokenReceiveContext> OnReceive { get; set; }
|
|
||||||
public Func<AuthenticationTokenReceiveContext, Task> OnReceiveAsync { get; set; }
|
|
||||||
|
|
||||||
public virtual void Create(AuthenticationTokenCreateContext context)
|
|
||||||
{
|
|
||||||
if (OnCreateAsync != null && OnCreate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Authentication token did not provide an OnCreate method.");
|
|
||||||
}
|
|
||||||
if (OnCreate != null)
|
|
||||||
{
|
|
||||||
OnCreate.Invoke(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual async Task CreateAsync(AuthenticationTokenCreateContext context)
|
|
||||||
{
|
|
||||||
if (OnCreateAsync != null && OnCreate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Authentication token did not provide an OnCreate method.");
|
|
||||||
}
|
|
||||||
if (OnCreateAsync != null)
|
|
||||||
{
|
|
||||||
await OnCreateAsync.Invoke(context);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Create(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Receive(AuthenticationTokenReceiveContext context)
|
|
||||||
{
|
|
||||||
if (OnReceiveAsync != null && OnReceive == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Authentication token did not provide an OnReceive method.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OnReceive != null)
|
|
||||||
{
|
|
||||||
OnReceive.Invoke(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
|
|
||||||
{
|
|
||||||
if (OnReceiveAsync != null && OnReceive == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Authentication token did not provide an OnReceive method.");
|
|
||||||
}
|
|
||||||
if (OnReceiveAsync != null)
|
|
||||||
{
|
|
||||||
await OnReceiveAsync.Invoke(context);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Receive(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
public class AuthenticationTokenReceiveContext : BaseContext
|
|
||||||
{
|
|
||||||
private readonly ISecureDataFormat<AuthenticationTicket> _secureDataFormat;
|
|
||||||
|
|
||||||
public AuthenticationTokenReceiveContext(HttpContext context, ISecureDataFormat<AuthenticationTicket> secureDataFormat, string token) : base(context)
|
|
||||||
{
|
|
||||||
if (secureDataFormat == null)
|
|
||||||
throw new ArgumentNullException(nameof(secureDataFormat));
|
|
||||||
|
|
||||||
if (token == null)
|
|
||||||
throw new ArgumentNullException(nameof(token));
|
|
||||||
|
|
||||||
_secureDataFormat = secureDataFormat;
|
|
||||||
|
|
||||||
Token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Token { get; protected set; }
|
|
||||||
|
|
||||||
public AuthenticationTicket Ticket { get; protected set; }
|
|
||||||
|
|
||||||
public void DeserializeTicket(string protectedData)
|
|
||||||
{
|
|
||||||
Ticket = _secureDataFormat.Unprotect(protectedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetTicket(AuthenticationTicket ticket)
|
|
||||||
{
|
|
||||||
if (ticket == null)
|
|
||||||
throw new ArgumentNullException(nameof(ticket));
|
|
||||||
|
|
||||||
Ticket = ticket;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Base class used for certain event contexts
|
|
||||||
/// </summary>
|
|
||||||
public abstract class BaseValidatingClientContext : BaseValidatingContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes base class used for certain event contexts
|
|
||||||
/// </summary>
|
|
||||||
protected BaseValidatingClientContext(HttpContext context, OAuthAuthorizationServerOptions options, string clientId) : base(context, options)
|
|
||||||
{
|
|
||||||
ClientId = clientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The "client_id" parameter for the current request. The Authorization Server application is responsible for
|
|
||||||
/// validating this value identifies a registered client.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientId { get; protected set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Base class used for certain event contexts
|
|
||||||
/// </summary>
|
|
||||||
public abstract class BaseValidatingContext<TOptions> : BaseContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes base class used for certain event contexts
|
|
||||||
/// </summary>
|
|
||||||
protected BaseValidatingContext(HttpContext context, TOptions options) : base(context)
|
|
||||||
{
|
|
||||||
Options = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The context options.
|
|
||||||
/// </summary>
|
|
||||||
public TOptions Options { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// True if application code has called any of the Validate methods on this context.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsValidated { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// True if application code has called any of the SetError methods on this context.
|
|
||||||
/// </summary>
|
|
||||||
public bool HasError { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The error argument provided when SetError was called on this context. This is eventually
|
|
||||||
/// returned to the client app as the OAuth "error" parameter.
|
|
||||||
/// </summary>
|
|
||||||
public string Error { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The optional errorDescription argument provided when SetError was called on this context. This is eventually
|
|
||||||
/// returned to the client app as the OAuth "error_description" parameter.
|
|
||||||
/// </summary>
|
|
||||||
public string ErrorDescription { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The optional errorUri argument provided when SetError was called on this context. This is eventually
|
|
||||||
/// returned to the client app as the OAuth "error_uri" parameter.
|
|
||||||
/// </summary>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "error_uri is a string value in the protocol")]
|
|
||||||
public string ErrorUri { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Marks this context as validated by the application. IsValidated becomes true and HasError becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>True if the validation has taken effect.</returns>
|
|
||||||
public virtual bool Validated()
|
|
||||||
{
|
|
||||||
IsValidated = true;
|
|
||||||
HasError = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Marks this context as not validated by the application. IsValidated and HasError become false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Rejected()
|
|
||||||
{
|
|
||||||
IsValidated = false;
|
|
||||||
HasError = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Marks this context as not validated by the application and assigns various error information properties.
|
|
||||||
/// HasError becomes true and IsValidated becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="error">Assigned to the Error property</param>
|
|
||||||
public void SetError(string error)
|
|
||||||
{
|
|
||||||
SetError(error, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Marks this context as not validated by the application and assigns various error information properties.
|
|
||||||
/// HasError becomes true and IsValidated becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="error">Assigned to the Error property</param>
|
|
||||||
/// <param name="errorDescription">Assigned to the ErrorDescription property</param>
|
|
||||||
public void SetError(string error, string errorDescription)
|
|
||||||
{
|
|
||||||
SetError(error, errorDescription, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Marks this context as not validated by the application and assigns various error information properties.
|
|
||||||
/// HasError becomes true and IsValidated becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="error">Assigned to the Error property</param>
|
|
||||||
/// <param name="errorDescription">Assigned to the ErrorDescription property</param>
|
|
||||||
/// <param name="errorUri">Assigned to the ErrorUri property</param>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "2#", Justification = "error_uri is a string value in the protocol")]
|
|
||||||
public void SetError(string error, string errorDescription, string errorUri)
|
|
||||||
{
|
|
||||||
Error = error;
|
|
||||||
ErrorDescription = errorDescription;
|
|
||||||
ErrorUri = errorUri;
|
|
||||||
Rejected();
|
|
||||||
HasError = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Http.Authentication;
|
|
||||||
using System.Security.Claims;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Base class used for certain event contexts
|
|
||||||
/// </summary>
|
|
||||||
public abstract class BaseValidatingTicketContext<TOptions> : BaseValidatingContext<TOptions> where TOptions : AuthenticationOptions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes base class used for certain event contexts
|
|
||||||
/// </summary>
|
|
||||||
protected BaseValidatingTicketContext(HttpContext context, TOptions options, AuthenticationTicket ticket) : base(context, options)
|
|
||||||
{
|
|
||||||
Ticket = ticket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains the identity and properties for the application to authenticate. If the Validated method
|
|
||||||
/// is invoked with an AuthenticationTicket or ClaimsIdentity argument, that new value is assigned to
|
|
||||||
/// this property in addition to changing IsValidated to true.
|
|
||||||
/// </summary>
|
|
||||||
public AuthenticationTicket Ticket { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Replaces the ticket information on this context and marks it as as validated by the application.
|
|
||||||
/// IsValidated becomes true and HasError becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ticket">Assigned to the Ticket property</param>
|
|
||||||
/// <returns>True if the validation has taken effect.</returns>
|
|
||||||
public bool Validated(AuthenticationTicket ticket)
|
|
||||||
{
|
|
||||||
Ticket = ticket;
|
|
||||||
return Validated();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Alters the ticket information on this context and marks it as as validated by the application.
|
|
||||||
/// IsValidated becomes true and HasError becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="principal">Assigned to the Ticket.Identity property</param>
|
|
||||||
/// <returns>True if the validation has taken effect.</returns>
|
|
||||||
public bool Validated(ClaimsPrincipal principal)
|
|
||||||
{
|
|
||||||
AuthenticationProperties properties = Ticket != null ? Ticket.Properties : new AuthenticationProperties();
|
|
||||||
return Validated(new AuthenticationTicket(principal, properties, Options.AuthenticationScheme));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static class DefaultBehavior
|
|
||||||
{
|
|
||||||
internal static readonly Func<OAuthValidateAuthorizeRequestContext, Task> ValidateAuthorizeRequest = context =>
|
|
||||||
{
|
|
||||||
context.Validated();
|
|
||||||
return Task.FromResult<object>(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
internal static readonly Func<OAuthValidateTokenRequestContext, Task> ValidateTokenRequest = context =>
|
|
||||||
{
|
|
||||||
context.Validated();
|
|
||||||
return Task.FromResult<object>(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
internal static readonly Func<OAuthGrantAuthorizationCodeContext, Task> GrantAuthorizationCode = context =>
|
|
||||||
{
|
|
||||||
if (context.Ticket != null && context.Ticket.Principal != null && context.Ticket.Principal.Identity.IsAuthenticated)
|
|
||||||
{
|
|
||||||
context.Validated();
|
|
||||||
}
|
|
||||||
return Task.FromResult<object>(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
internal static readonly Func<OAuthGrantRefreshTokenContext, Task> GrantRefreshToken = context =>
|
|
||||||
{
|
|
||||||
if (context.Ticket != null && context.Ticket.Principal != null && context.Ticket.Principal.Identity.IsAuthenticated)
|
|
||||||
{
|
|
||||||
context.Validated();
|
|
||||||
}
|
|
||||||
return Task.FromResult<object>(null);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
public interface IAuthenticationTokenProvider
|
|
||||||
{
|
|
||||||
void Create(AuthenticationTokenCreateContext context);
|
|
||||||
Task CreateAsync(AuthenticationTokenCreateContext context);
|
|
||||||
void Receive(AuthenticationTokenReceiveContext context);
|
|
||||||
Task ReceiveAsync(AuthenticationTokenReceiveContext context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
SOURCE_DIR=../..
|
|
||||||
MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make
|
|
||||||
include $(MAKEFILE_DIR)/dnx.mk
|
|
||||||
include $(MAKEFILE_DIR)/versioning.mk
|
|
||||||
|
|
||||||
all: $(BINTARGETPATH)
|
|
||||||
|
|
@ -1,136 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.DataProtection;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Options class provides information needed to control Authorization Server middleware behavior
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthAuthorizationServerOptions : AuthenticationOptions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an instance of authorization server options with default values.
|
|
||||||
/// </summary>
|
|
||||||
public OAuthAuthorizationServerOptions()
|
|
||||||
{
|
|
||||||
AuthenticationScheme = OAuthDefaults.AuthenticationType;
|
|
||||||
AuthorizationCodeExpireTimeSpan = TimeSpan.FromMinutes(5);
|
|
||||||
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(20);
|
|
||||||
SystemClock = new SystemClock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The request path where client applications will redirect the user-agent in order to
|
|
||||||
/// obtain user consent to issue a token. Must begin with a leading slash, like "/Authorize".
|
|
||||||
/// </summary>
|
|
||||||
public PathString AuthorizeEndpointPath { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The request path client applications communicate with directly as part of the OAuth protocol.
|
|
||||||
/// Must begin with a leading slash, like "/Token". If the client is issued a client_secret, it must
|
|
||||||
/// be provided to this endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public PathString TokenEndpointPath { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The object provided by the application to process events raised by the Authorization Server middleware.
|
|
||||||
/// The application may implement the interface fully, or it may create an instance of OAuthAuthorizationServerProvider
|
|
||||||
/// and assign delegates only to the events it wants to process.
|
|
||||||
/// </summary>
|
|
||||||
public IOAuthAuthorizationServerProvider Provider { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The data format used to protect and unprotect the information contained in the authorization code.
|
|
||||||
/// If not provided by the application the default data protection provider depends on the host server.
|
|
||||||
/// The SystemWeb host on IIS will use ASP.NET machine key data protection, and HttpListener and other self-hosted
|
|
||||||
/// servers will use DPAPI data protection.
|
|
||||||
/// </summary>
|
|
||||||
public ISecureDataFormat<AuthenticationTicket> AuthorizationCodeFormat { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The data protection provider used to protect token information.
|
|
||||||
/// </summary>
|
|
||||||
public IDataProtector TokenDataProtector { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The data format used to protect the information contained in the access token.
|
|
||||||
/// If not provided by the application the default data protection provider depends on the host server.
|
|
||||||
/// The SystemWeb host on IIS will use ASP.NET machine key data protection, and HttpListener and other self-hosted
|
|
||||||
/// servers will use DPAPI data protection. If a different access token
|
|
||||||
/// provider or format is assigned, a compatible instance must be assigned to the OAuthBearerAuthenticationOptions.AccessTokenProvider
|
|
||||||
/// or OAuthBearerAuthenticationOptions.AccessTokenFormat property of the resource server.
|
|
||||||
/// </summary>
|
|
||||||
public ISecureDataFormat<AuthenticationTicket> AccessTokenFormat { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The data format used to protect and unprotect the information contained in the refresh token.
|
|
||||||
/// If not provided by the application the default data protection provider depends on the host server.
|
|
||||||
/// The SystemWeb host on IIS will use ASP.NET machine key data protection, and HttpListener and other self-hosted
|
|
||||||
/// servers will use DPAPI data protection.
|
|
||||||
/// </summary>
|
|
||||||
public ISecureDataFormat<AuthenticationTicket> RefreshTokenFormat { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The period of time the authorization code remains valid after being issued. The default is five minutes.
|
|
||||||
/// This time span must also take into account clock synchronization between servers in a web farm, so a very
|
|
||||||
/// brief value could result in unexpectedly expired tokens.
|
|
||||||
/// </summary>
|
|
||||||
public TimeSpan AuthorizationCodeExpireTimeSpan { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The period of time the access token remains valid after being issued. The default is twenty minutes.
|
|
||||||
/// The client application is expected to refresh or acquire a new access token after the token has expired.
|
|
||||||
/// </summary>
|
|
||||||
public TimeSpan AccessTokenExpireTimeSpan { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Produces a single-use authorization code to return to the client application. For the OAuth server to be secure the
|
|
||||||
/// application MUST provide an instance for AuthorizationCodeProvider where the token produced by the OnCreate or OnCreateAsync event
|
|
||||||
/// is considered valid for only one call to OnReceive or OnReceiveAsync.
|
|
||||||
/// </summary>
|
|
||||||
public IAuthenticationTokenProvider AuthorizationCodeProvider { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Produces a bearer token the client application will typically be providing to resource server as the authorization bearer
|
|
||||||
/// http request header. If not provided the token produced on the server's default data protection. If a different access token
|
|
||||||
/// provider or format is assigned, a compatible instance must be assigned to the OAuthBearerAuthenticationOptions.AccessTokenProvider
|
|
||||||
/// or OAuthBearerAuthenticationOptions.AccessTokenFormat property of the resource server.
|
|
||||||
/// </summary>
|
|
||||||
public IAuthenticationTokenProvider AccessTokenProvider { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Produces a refresh token which may be used to produce a new access token when needed. If not provided the authorization server will
|
|
||||||
/// not return refresh tokens from the /Token endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public IAuthenticationTokenProvider RefreshTokenProvider { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set to true if the web application is able to render error messages on the /Authorize endpoint. This is only needed for cases where
|
|
||||||
/// the browser is not redirected back to the client application, for example, when the client_id or redirect_uri are incorrect. The
|
|
||||||
/// /Authorize endpoint should expect to see "oauth.Error", "oauth.ErrorDescription", "oauth.ErrorUri" properties added to the owin environment.
|
|
||||||
/// </summary>
|
|
||||||
public bool ApplicationCanDisplayErrors { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Used to know what the current clock time is when calculating or validating token expiration. When not assigned default is based on
|
|
||||||
/// DateTimeOffset.UtcNow. This is typically needed only for unit testing.
|
|
||||||
/// </summary>
|
|
||||||
public ISystemClock SystemClock { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// True to allow authorize and token requests to arrive on http URI addresses, and to allow incoming
|
|
||||||
/// redirect_uri authorize request parameter to have http URI addresses.
|
|
||||||
/// </summary>
|
|
||||||
public bool AllowInsecureHttp { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Endpoint responsible for Form Post Response Mode
|
|
||||||
/// See also, http://openid.net/specs/oauth-v2-form-post-response-mode-1_0.html
|
|
||||||
/// </summary>
|
|
||||||
public PathString FormPostEndpoint { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// An event raised after the Authorization Server has processed the request, but before it is passed on to the web application.
|
|
||||||
/// Calling RequestCompleted will prevent the request from passing on to the web application.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthAuthorizeEndpointContext : BaseOAuthEndpointContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an instance of this context
|
|
||||||
/// </summary>
|
|
||||||
public OAuthAuthorizeEndpointContext(HttpContext context, OAuthAuthorizationServerOptions options, AuthorizeEndpointRequest authorizeRequest) : base(context, options)
|
|
||||||
{
|
|
||||||
AuthorizeRequest = authorizeRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets OAuth authorization request data.
|
|
||||||
/// </summary>
|
|
||||||
public AuthorizeEndpointRequest AuthorizeRequest { get; private set; }
|
|
||||||
|
|
||||||
public bool IsRequestCompleted { get; private set; }
|
|
||||||
|
|
||||||
public void RequestCompleted()
|
|
||||||
{
|
|
||||||
IsRequestCompleted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information when handling an OAuth authorization code grant.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthGrantAuthorizationCodeContext : BaseValidatingTicketContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthGrantAuthorizationCodeContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="ticket"></param>
|
|
||||||
public OAuthGrantAuthorizationCodeContext(HttpContext context, OAuthAuthorizationServerOptions options, AuthenticationTicket ticket) : base(context, options, ticket) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used in handling an OAuth client credentials grant.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthGrantClientCredentialsContext : BaseValidatingTicketContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthGrantClientCredentialsContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <param name="scope"></param>
|
|
||||||
public OAuthGrantClientCredentialsContext(HttpContext context, OAuthAuthorizationServerOptions options, string clientId, IList<string> scope) : base(context, options, null)
|
|
||||||
{
|
|
||||||
ClientId = clientId;
|
|
||||||
Scope = scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// OAuth client id.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientId { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// List of scopes allowed by the resource owner.
|
|
||||||
/// </summary>
|
|
||||||
public IList<string> Scope { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used when handling OAuth extension grant types.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthGrantCustomExtensionContext : BaseValidatingTicketContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthGrantCustomExtensionContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <param name="grantType"></param>
|
|
||||||
/// <param name="parameters"></param>
|
|
||||||
public OAuthGrantCustomExtensionContext(HttpContext context, OAuthAuthorizationServerOptions options, string clientId, string grantType, IReadableStringCollection parameters) : base(context, options, null)
|
|
||||||
{
|
|
||||||
ClientId = clientId;
|
|
||||||
GrantType = grantType;
|
|
||||||
Parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the OAuth client id.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientId { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the name of the OAuth extension grant type.
|
|
||||||
/// </summary>
|
|
||||||
public string GrantType { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a list of additional parameters from the token request.
|
|
||||||
/// </summary>
|
|
||||||
public IReadableStringCollection Parameters { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used when granting an OAuth refresh token.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthGrantRefreshTokenContext : BaseValidatingTicketContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthGrantRefreshTokenContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="ticket"></param>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
public OAuthGrantRefreshTokenContext(HttpContext context, OAuthAuthorizationServerOptions options, AuthenticationTicket ticket, string clientId) : base(context, options, ticket)
|
|
||||||
{
|
|
||||||
ClientId = clientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The OAuth client id.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientId { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used in handling an OAuth resource owner grant.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthGrantResourceOwnerCredentialsContext : BaseValidatingTicketContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthGrantResourceOwnerCredentialsContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <param name="userName"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
/// <param name="scope"></param>
|
|
||||||
public OAuthGrantResourceOwnerCredentialsContext(HttpContext context, OAuthAuthorizationServerOptions options, string clientId, string userName, string password, IList<string> scope) : base(context, options, null)
|
|
||||||
{
|
|
||||||
ClientId = clientId;
|
|
||||||
UserName = userName;
|
|
||||||
Password = password;
|
|
||||||
Scope = scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// OAuth client id.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientId { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Resource owner username.
|
|
||||||
/// </summary>
|
|
||||||
public string UserName { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Resource owner password.
|
|
||||||
/// </summary>
|
|
||||||
public string Password { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// List of scopes allowed by the resource owner.
|
|
||||||
/// </summary>
|
|
||||||
public IList<string> Scope { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides notification used for determining the OAuth flow type based on the request.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthMatchContext : BaseControlContext
|
|
||||||
{
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthMatchContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
public OAuthMatchContext(HttpContext context, OAuthAuthorizationServerOptions options) : base(context)
|
|
||||||
{
|
|
||||||
if (options == null)
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
|
|
||||||
Options = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
public OAuthAuthorizationServerOptions Options { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether or not the endpoint is an OAuth authorize endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsAuthorizeEndpoint { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether or not the endpoint is an OAuth token endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsTokenEndpoint { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the endpoint type to authorize endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public void MatchesAuthorizeEndpoint()
|
|
||||||
{
|
|
||||||
IsAuthorizeEndpoint = true;
|
|
||||||
IsTokenEndpoint = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the endpoint type to token endpoint.
|
|
||||||
/// </summary>
|
|
||||||
public void MatchesTokenEndpoint()
|
|
||||||
{
|
|
||||||
IsAuthorizeEndpoint = false;
|
|
||||||
IsTokenEndpoint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the endpoint type to neither authorize nor token.
|
|
||||||
/// </summary>
|
|
||||||
public void MatchesNothing()
|
|
||||||
{
|
|
||||||
IsAuthorizeEndpoint = false;
|
|
||||||
IsTokenEndpoint = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Http.Authentication;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Security.Claims;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used when processing an OAuth token request.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthTokenEndpointContext : BaseOAuthEndpointContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthTokenEndpointContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="ticket"></param>
|
|
||||||
/// <param name="tokenEndpointRequest"></param>
|
|
||||||
public OAuthTokenEndpointContext(HttpContext context, OAuthAuthorizationServerOptions options, AuthenticationTicket ticket, TokenEndpointRequest tokenEndpointRequest) : base(context, options)
|
|
||||||
{
|
|
||||||
if (ticket == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("ticket");
|
|
||||||
}
|
|
||||||
|
|
||||||
Principal = ticket.Principal;
|
|
||||||
Properties = ticket.Properties;
|
|
||||||
TokenEndpointRequest = tokenEndpointRequest;
|
|
||||||
AdditionalResponseParameters = new Dictionary<string, object>(StringComparer.Ordinal);
|
|
||||||
TokenIssued = Principal != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the identity of the resource owner.
|
|
||||||
/// </summary>
|
|
||||||
public ClaimsPrincipal Principal { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Dictionary containing the state of the authentication session.
|
|
||||||
/// </summary>
|
|
||||||
public AuthenticationProperties Properties { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets information about the token endpoint request.
|
|
||||||
/// </summary>
|
|
||||||
public TokenEndpointRequest TokenEndpointRequest { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether or not the token should be issued.
|
|
||||||
/// </summary>
|
|
||||||
public bool TokenIssued { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enables additional values to be appended to the token response.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, object> AdditionalResponseParameters { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Issues the token.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="principal"></param>
|
|
||||||
/// <param name="properties"></param>
|
|
||||||
public void Issue(ClaimsPrincipal principal, AuthenticationProperties properties)
|
|
||||||
{
|
|
||||||
Principal = principal;
|
|
||||||
Properties = properties;
|
|
||||||
TokenIssued = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used in validating an OAuth authorization request.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthValidateAuthorizeRequestContext : BaseValidatingContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthValidateAuthorizeRequestContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="authorizeRequest"></param>
|
|
||||||
/// <param name="clientContext"></param>
|
|
||||||
public OAuthValidateAuthorizeRequestContext(HttpContext context, OAuthAuthorizationServerOptions options, AuthorizeEndpointRequest authorizeRequest, OAuthValidateClientRedirectUriContext clientContext) : base(context, options)
|
|
||||||
{
|
|
||||||
AuthorizeRequest = authorizeRequest;
|
|
||||||
ClientContext = clientContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets OAuth authorization request data.
|
|
||||||
/// </summary>
|
|
||||||
public AuthorizeEndpointRequest AuthorizeRequest { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets data about the OAuth client.
|
|
||||||
/// </summary>
|
|
||||||
public OAuthValidateClientRedirectUriContext ClientContext { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains information about the client credentials.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthValidateClientAuthenticationContext : BaseValidatingClientContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthValidateClientAuthenticationContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="parameters"></param>
|
|
||||||
public OAuthValidateClientAuthenticationContext(HttpContext context, OAuthAuthorizationServerOptions options, IReadableStringCollection parameters) : base(context, options, null)
|
|
||||||
{
|
|
||||||
Parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the set of form parameters from the request.
|
|
||||||
/// </summary>
|
|
||||||
public IReadableStringCollection Parameters { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the client id and marks the context as validated by the application.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Validated(string clientId)
|
|
||||||
{
|
|
||||||
ClientId = clientId;
|
|
||||||
|
|
||||||
return Validated();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extracts HTTP basic authentication credentials from the HTTP authenticate header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <param name="clientSecret"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#", Justification = "Optimized for usage")]
|
|
||||||
public bool TryGetBasicCredentials(out string clientId, out string clientSecret)
|
|
||||||
{
|
|
||||||
// Client Authentication http://tools.ietf.org/html/rfc6749#section-2.3
|
|
||||||
// Client Authentication Password http://tools.ietf.org/html/rfc6749#section-2.3.1
|
|
||||||
string authorization = Request.Headers["Authorization"];
|
|
||||||
if (!string.IsNullOrWhiteSpace(authorization) && authorization.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] data = Convert.FromBase64String(authorization.Substring("Basic ".Length).Trim());
|
|
||||||
string text = Encoding.UTF8.GetString(data);
|
|
||||||
int delimiterIndex = text.IndexOf(':');
|
|
||||||
if (delimiterIndex >= 0)
|
|
||||||
{
|
|
||||||
clientId = text.Substring(0, delimiterIndex);
|
|
||||||
clientSecret = text.Substring(delimiterIndex + 1);
|
|
||||||
ClientId = clientId;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
// Bad Base64 string
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
// Bad utf-8 string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clientId = null;
|
|
||||||
clientSecret = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extracts forms authentication credentials from the HTTP request body.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <param name="clientSecret"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#", Justification = "Optimized for usage")]
|
|
||||||
public bool TryGetFormCredentials(out string clientId, out string clientSecret)
|
|
||||||
{
|
|
||||||
clientId = Parameters[Constants.Parameters.ClientId];
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(clientId))
|
|
||||||
{
|
|
||||||
clientSecret = Parameters[Constants.Parameters.ClientSecret];
|
|
||||||
ClientId = clientId;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
clientId = null;
|
|
||||||
clientSecret = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains data about the OAuth client redirect URI
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthValidateClientRedirectUriContext : BaseValidatingClientContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthValidateClientRedirectUriContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="clientId"></param>
|
|
||||||
/// <param name="redirectUri"></param>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "3#", Justification = "redirect_uri is a string parameter")]
|
|
||||||
public OAuthValidateClientRedirectUriContext(HttpContext context, OAuthAuthorizationServerOptions options, string clientId, string redirectUri) : base(context, options, clientId)
|
|
||||||
{
|
|
||||||
RedirectUri = redirectUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the client redirect URI
|
|
||||||
/// </summary>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "redirect_uri is a string parameter")]
|
|
||||||
public string RedirectUri { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Marks this context as validated by the application. IsValidated becomes true and HasError becomes false as a result of calling.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override bool Validated()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(RedirectUri))
|
|
||||||
{
|
|
||||||
// Don't allow default validation when redirect_uri not provided with request
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return base.Validated();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks the redirect URI to determine whether it equals <see cref="RedirectUri"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="redirectUri"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Justification = "redirect_uri is a string parameter")]
|
|
||||||
public bool Validated(string redirectUri)
|
|
||||||
{
|
|
||||||
if (redirectUri == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("redirectUri");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(RedirectUri) &&
|
|
||||||
!string.Equals(RedirectUri, redirectUri, StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
// Don't allow validation to alter redirect_uri provided with request
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
RedirectUri = redirectUri;
|
|
||||||
|
|
||||||
return Validated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides context information used in validating an OAuth token request.
|
|
||||||
/// </summary>
|
|
||||||
public class OAuthValidateTokenRequestContext : BaseValidatingContext<OAuthAuthorizationServerOptions>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="OAuthValidateTokenRequestContext"/> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
/// <param name="tokenRequest"></param>
|
|
||||||
/// <param name="clientContext"></param>
|
|
||||||
public OAuthValidateTokenRequestContext(HttpContext context, OAuthAuthorizationServerOptions options, TokenEndpointRequest tokenRequest, BaseValidatingClientContext clientContext) : base(context, options)
|
|
||||||
{
|
|
||||||
TokenRequest = tokenRequest;
|
|
||||||
ClientContext = clientContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the token request data.
|
|
||||||
/// </summary>
|
|
||||||
public TokenEndpointRequest TokenRequest { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets information about the client.
|
|
||||||
/// </summary>
|
|
||||||
public BaseValidatingClientContext ClientContext { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Data object used by TokenEndpointRequest when the "grant_type" is "authorization_code".
|
|
||||||
/// </summary>
|
|
||||||
public class TokenEndpointRequestAuthorizationCode
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "code" parameter
|
|
||||||
/// </summary>
|
|
||||||
public string Code { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "redirect_uri" parameter. This MUST be provided by the caller
|
|
||||||
/// if the original visit to the Authorize endpoint contained a "redirect_uri" parameter.
|
|
||||||
/// </summary>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "By design")]
|
|
||||||
public string RedirectUri { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Data object used by TokenEndpointRequest when the "grant_type" is "client_credentials".
|
|
||||||
/// </summary>
|
|
||||||
public class TokenEndpointRequestClientCredentials
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "scope" parameter
|
|
||||||
/// </summary>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This class is just for passing data through.")]
|
|
||||||
public IList<string> Scope { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Data object used by TokenEndpointRequest when the "grant_type" parameter is "refresh_token".
|
|
||||||
/// </summary>
|
|
||||||
public class TokenEndpointRequestRefreshToken
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "refresh_token" parameter
|
|
||||||
/// </summary>
|
|
||||||
public string RefreshToken { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "scope" parameter
|
|
||||||
/// </summary>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This is just a data container object.")]
|
|
||||||
public IList<string> Scope { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace OAuth.AspNet.AuthServer
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Data object used by TokenEndpointRequest when the "grant_type" is "password".
|
|
||||||
/// </summary>
|
|
||||||
public class TokenEndpointRequestResourceOwnerPasswordCredentials
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "username" parameter
|
|
||||||
/// </summary>
|
|
||||||
public string UserName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "password" parameter
|
|
||||||
/// </summary>
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The value passed to the Token endpoint in the "scope" parameter
|
|
||||||
/// </summary>
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This is just a data class.")]
|
|
||||||
public IList<string> Scope { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.5-*",
|
|
||||||
"description": "OAuth AspNet Server",
|
|
||||||
"authors": [
|
|
||||||
"Paul Schneider <paul@pschneider.fr>"
|
|
||||||
],
|
|
||||||
"packOptions": {
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/pazof/yavsc"
|
|
||||||
},
|
|
||||||
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
|
|
||||||
"requireLicenseAcceptance": true,
|
|
||||||
"owners": [
|
|
||||||
"Paul Schneider <paul@pschneider.fr>"
|
|
||||||
],
|
|
||||||
"summary": "Yet another very small company",
|
|
||||||
"projectUrl": "http://yavsc.pschneider.fr",
|
|
||||||
"tags": [
|
|
||||||
"Authorization server",
|
|
||||||
"OAuth",
|
|
||||||
"Web API"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"tooling": {
|
|
||||||
"defaultNamespace": "Yavsc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"Newtonsoft.Json": "7.0.1",
|
|
||||||
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
|
|
||||||
"OAuth.AspNet.Token": {
|
|
||||||
"type": "build",
|
|
||||||
"target": "project"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"dnx451": {
|
|
||||||
"frameworkAssemblies": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
SOURCE_DIR=../..
|
|
||||||
MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make
|
|
||||||
|
|
||||||
include $(MAKEFILE_DIR)/dnx.mk
|
|
||||||
include $(MAKEFILE_DIR)/versioning.mk
|
|
||||||
|
|
||||||
all: $(BINTARGETPATH)
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.AspNet.DataProtection;
|
|
||||||
|
|
||||||
public class MonoDataProtectionProvider : IDataProtectionProvider
|
|
||||||
{
|
|
||||||
private readonly string appName;
|
|
||||||
|
|
||||||
public MonoDataProtectionProvider()
|
|
||||||
: this(Guid.NewGuid().ToString())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public MonoDataProtectionProvider(DirectoryInfo dataProtectionDirInfo)
|
|
||||||
: this(Guid.NewGuid().ToString())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public MonoDataProtectionProvider(string appName)
|
|
||||||
{
|
|
||||||
if (appName == null) { throw new ArgumentNullException("appName"); }
|
|
||||||
this.appName = appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDataProtector Create(params string[] purposes)
|
|
||||||
{
|
|
||||||
if (purposes == null) { throw new ArgumentNullException("profile"); }
|
|
||||||
|
|
||||||
return new MonoDataProtector(appName, purposes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDataProtector CreateProtector(string purpose)
|
|
||||||
{
|
|
||||||
return Create(new string[] { purpose });
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
//
|
|
||||||
// MonoDataProtector.cs
|
|
||||||
//
|
|
||||||
// Author:
|
|
||||||
// Paul Schneider <paul@pschneider.fr>
|
|
||||||
//
|
|
||||||
// Copyright (c) 2016 GNU GPL
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.AspNet.DataProtection;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
public class MonoDataProtector : IDataProtector
|
|
||||||
{
|
|
||||||
private const string PRIMARY_PURPOSE = "IDataProtector";
|
|
||||||
|
|
||||||
private readonly string appName;
|
|
||||||
private readonly DataProtectionScope dataProtectionScope;
|
|
||||||
private readonly string[] purposes;
|
|
||||||
|
|
||||||
public MonoDataProtector(string appName, string[] purposes)
|
|
||||||
{
|
|
||||||
if (appName == null) { throw new ArgumentNullException("appName"); }
|
|
||||||
if (purposes == null) { throw new ArgumentNullException("purposes"); }
|
|
||||||
|
|
||||||
this.appName = appName;
|
|
||||||
this.purposes = purposes;
|
|
||||||
this.dataProtectionScope = DataProtectionScope.CurrentUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDataProtector CreateProtector(string purpose)
|
|
||||||
{
|
|
||||||
if (purposes.Contains(purpose))
|
|
||||||
return new MonoDataProtector(appName, new string[] { purpose });
|
|
||||||
return new MonoDataProtector(appName, new string[] { });
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Protect(byte[] userData)
|
|
||||||
{
|
|
||||||
return ProtectedData.Protect(userData, this.GetEntropy(), dataProtectionScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Unprotect(byte[] protectedData)
|
|
||||||
{
|
|
||||||
return ProtectedData.Unprotect(protectedData, this.GetEntropy(), dataProtectionScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] GetEntropy()
|
|
||||||
{
|
|
||||||
using (SHA256 sha256 = SHA256.Create())
|
|
||||||
{
|
|
||||||
using (MemoryStream memoryStream = new MemoryStream())
|
|
||||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, sha256, CryptoStreamMode.Write))
|
|
||||||
using (StreamWriter writer = new StreamWriter(cryptoStream))
|
|
||||||
{
|
|
||||||
writer.Write(this.appName);
|
|
||||||
writer.Write(PRIMARY_PURPOSE);
|
|
||||||
|
|
||||||
foreach (string purpose in this.purposes)
|
|
||||||
{
|
|
||||||
writer.Write(purpose);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sha256.Hash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.5-*",
|
|
||||||
"description": "OAuth AspNet Token",
|
|
||||||
"authors": [
|
|
||||||
"Paul Schneider <paul@pschneider.fr>"
|
|
||||||
],
|
|
||||||
"packOptions": {
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/pazof/yavsc"
|
|
||||||
},
|
|
||||||
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
|
|
||||||
"requireLicenseAcceptance": true,
|
|
||||||
"owners": [
|
|
||||||
"Paul Schneider <paul@pschneider.fr>"
|
|
||||||
],
|
|
||||||
"summary": "Yet another very small company",
|
|
||||||
"projectUrl": "http://yavsc.pschneider.fr",
|
|
||||||
"tags": [
|
|
||||||
"Authorization server",
|
|
||||||
"OAuth",
|
|
||||||
"Web API"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"tooling": {
|
|
||||||
"defaultNamespace": "Yavsc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"Newtonsoft.Json": "7.0.1",
|
|
||||||
"Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final",
|
|
||||||
"Microsoft.AspNet.DataProtection": "1.0.0-rc1-final"
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"dnx451": {
|
|
||||||
"frameworkAssemblies": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"postrestore": [
|
|
||||||
"grep -v '\\.\\.dll' project.lock.json > new.project.lock.json",
|
|
||||||
"mv new.project.lock.json project.lock.json"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Google.Apis.Calendar.v3" Version="1.60.0.2993" />
|
||||||
|
<PackageReference Include="PayPalMerchantSDK" Version="2.16.250" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.Net" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../Yavsc.Abstract/Yavsc.Abstract.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
Loading…
Reference in New Issue