63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using DotNetOpenAuth.Messaging;
|
|
using DotNetOpenAuth.OAuth2;
|
|
using Microsoft.Practices.ServiceLocation;
|
|
using Taloyhtio.GeneralSSO.Server.CodeFiles.Common;
|
|
using Taloyhtio.GeneralSSO.Server.CodeFiles.Services;
|
|
|
|
namespace Taloyhtio.GeneralSSO.Server.CodeFiles.Entities
|
|
{
|
|
public class Client : PersistentObject<int>, IClientDescription
|
|
{
|
|
public virtual string ClientIdentifier { get; set; }
|
|
public virtual string ClientSecret { get; set; }
|
|
public virtual string Callback { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual ClientType ClientType { get; set; }
|
|
public virtual IList<ClientAuthorization> ClientAuthorizations { get; set; }
|
|
|
|
public virtual bool IsCallbackAllowed(Uri callback)
|
|
{
|
|
try
|
|
{
|
|
if (callback == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(this.Callback))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var uri = new Uri(this.Callback);
|
|
return (string.Compare(callback.GetLeftPart(UriPartial.Authority),
|
|
uri.GetLeftPart(UriPartial.Authority), true) == 0);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
ServiceLocator.Current.GetInstance<ILogger>().Error(Constants.LogComponents.CLIENT_ENTITY, x);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public virtual bool IsValidClientSecret(string secret)
|
|
{
|
|
return MessagingUtilities.EqualsConstantTime(secret, this.ClientSecret);
|
|
}
|
|
|
|
public virtual Uri DefaultCallback
|
|
{
|
|
get { return new Uri(this.Callback); }
|
|
}
|
|
|
|
public virtual bool HasNonEmptySecret
|
|
{
|
|
get { return !string.IsNullOrEmpty(this.ClientSecret); }
|
|
}
|
|
}
|
|
}
|