diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-07-31 22:01:16 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-07-31 22:01:16 -0700 |
commit | c94c7f8197eda673947a9d1e0c0b3f3c4efca94f (patch) | |
tree | 0f978cfc2de70c54ac81e11d4339da04dff9f27f /samples/OAuthServiceProvider/Code | |
parent | 7d38eefb65928a1e80036ec006b0e129dc2cface (diff) | |
download | DotNetOpenAuth-c94c7f8197eda673947a9d1e0c0b3f3c4efca94f.zip DotNetOpenAuth-c94c7f8197eda673947a9d1e0c0b3f3c4efca94f.tar.gz DotNetOpenAuth-c94c7f8197eda673947a9d1e0c0b3f3c4efca94f.tar.bz2 |
Split the OAuthServiceProvider sample into two samples: OAuthAuthorizationServer and OAuthResourceServer.
Renamed OAuthConsumer to OAuthClient.
Diffstat (limited to 'samples/OAuthServiceProvider/Code')
12 files changed, 0 insertions, 1656 deletions
diff --git a/samples/OAuthServiceProvider/Code/Client.cs b/samples/OAuthServiceProvider/Code/Client.cs deleted file mode 100644 index bb4007e..0000000 --- a/samples/OAuthServiceProvider/Code/Client.cs +++ /dev/null @@ -1,40 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="Client.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Web; - using DotNetOpenAuth.OAuth2; - - public partial class Client : IConsumerDescription { - #region IConsumerDescription Members - - /// <summary> - /// Gets the client secret. - /// </summary> - string IConsumerDescription.Secret { - get { return this.ClientSecret; } - } - - /// <summary> - /// Gets the allowed callback URIs that this client has pre-registered with the service provider, if any. - /// </summary> - /// <value> - /// The URIs that user authorization responses may be directed to; must not be <c>null</c>, but may be empty. - /// </value> - /// <remarks> - /// The first element in this list (if any) will be used as the default client redirect URL if the client sends an authorization request without a redirect URL. - /// If the list is empty, any callback is allowed for this client. - /// </remarks> - List<Uri> IConsumerDescription.AllowedCallbacks { - get { return string.IsNullOrEmpty(this.Callback) ? new List<Uri>() : new List<Uri>(new Uri[] { new Uri(this.Callback) }); } - } - - #endregion - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/DataClasses.dbml b/samples/OAuthServiceProvider/Code/DataClasses.dbml deleted file mode 100644 index 906d91d..0000000 --- a/samples/OAuthServiceProvider/Code/DataClasses.dbml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?><Database Name="Database" EntityNamespace="OAuthServiceProvider.Code" Class="DataClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007"> - <Connection Mode="WebSettings" ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database4.mdf;Integrated Security=True;User Instance=True" SettingsObjectName="System.Configuration.ConfigurationManager.ConnectionStrings" SettingsPropertyName="DatabaseConnectionString" Provider="System.Data.SqlClient" /> - <Table Name="dbo.[User]" Member="Users"> - <Type Name="User"> - <Column Name="UserId" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> - <Column Name="OpenIDClaimedIdentifier" Type="System.String" DbType="NVarChar(150) NOT NULL" CanBeNull="false" /> - <Column Name="OpenIDFriendlyIdentifier" Type="System.String" DbType="NVarChar(150)" CanBeNull="true" /> - <Column Name="FullName" Type="System.String" DbType="NVarChar(150)" CanBeNull="false" /> - <Column Name="Age" Type="System.Int32" DbType="int" CanBeNull="true" /> - <Association Name="User_FavoriteSite" Member="FavoriteSites" ThisKey="UserId" OtherKey="UserId" Type="FavoriteSite" /> - <Association Name="User_ClientAuthorization" Member="ClientAuthorizations" Storage="_OAuthTokens" ThisKey="UserId" OtherKey="UserId" Type="ClientAuthorization" /> - </Type> - </Table> - <Table Name="dbo.FavoriteSite" Member="FavoriteSites"> - <Type Name="FavoriteSite"> - <Column Name="FavoriteSiteId" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> - <Column Name="UserId" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> - <Column Name="SiteUrl" Type="System.String" DbType="NVarChar(255) NOT NULL" CanBeNull="false" /> - <Association Name="User_FavoriteSite" Member="User" ThisKey="UserId" OtherKey="UserId" Type="User" IsForeignKey="true" DeleteRule="CASCADE" DeleteOnNull="true" /> - </Type> - </Table> - <Table Name="dbo.Client" Member="Clients"> - <Type Name="Client"> - <Column Name="ClientId" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> - <Column Name="ClientIdentifier" Type="System.String" DbType="NVarChar(50) NOT NULL" CanBeNull="false" /> - <Column Name="ClientSecret" Type="System.String" DbType="NVarChar(50) NOT NULL" CanBeNull="false" /> - <Column Name="Callback" Type="System.String" CanBeNull="true" /> - <Column Name="Name" Type="System.String" CanBeNull="false" /> - <Association Name="Client_ClientAuthorization" Member="ClientAuthorizations" Storage="_OAuthTokens" ThisKey="ClientId" OtherKey="ClientId" Type="ClientAuthorization" /> - </Type> - </Table> - <Table Name="dbo.ClientAuthorization" Member="ClientAuthorizations"> - <Type Name="ClientAuthorization"> - <Column Name="AuthorizationId" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> - <Column Name="CreatedOnUtc" Storage="_IssueDate" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" /> - <Column Name="ClientId" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> - <Column Name="UserId" Type="System.Int32" DbType="Int" CanBeNull="true" /> - <Column Name="Scope" Type="System.String" DbType="nvarchar(MAX)" CanBeNull="false" /> - <Column Name="ExpirationDateUtc" Type="System.DateTime" DbType="DateTime NULL" CanBeNull="true" /> - <Association Name="Client_ClientAuthorization" Member="Client" ThisKey="ClientId" OtherKey="ClientId" Type="Client" IsForeignKey="true" DeleteRule="CASCADE" DeleteOnNull="true" /> - <Association Name="User_ClientAuthorization" Member="User" ThisKey="UserId" OtherKey="UserId" Type="User" IsForeignKey="true" DeleteRule="CASCADE" /> - </Type> - </Table> - <Table Name="dbo.Nonce" Member="Nonces"> - <Type Name="Nonce"> - <Column Name="Context" Type="System.String" IsPrimaryKey="true" CanBeNull="false" /> - <Column Name="Code" Type="System.String" IsPrimaryKey="true" CanBeNull="false" /> - <Column Name="Timestamp" Type="System.DateTime" IsPrimaryKey="true" CanBeNull="false" /> - </Type> - </Table> -</Database>
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/DataClasses.dbml.layout b/samples/OAuthServiceProvider/Code/DataClasses.dbml.layout deleted file mode 100644 index 346bb49..0000000 --- a/samples/OAuthServiceProvider/Code/DataClasses.dbml.layout +++ /dev/null @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 11, 8.5" name="DataClasses"> - <DataContextMoniker Name="/DataClassesDataContext" /> - <nestedChildShapes> - <classShape Id="696d2c69-040e-411d-9257-bb664b743834" absoluteBounds="0.5, 0.5, 2.125, 1.7708968098958331"> - <DataClassMoniker Name="/DataClassesDataContext/User" /> - <nestedChildShapes> - <elementListCompartment Id="cd90aeff-476c-44a9-897f-a986e4a8305b" absoluteBounds="0.515, 0.96, 2.0949999999999998, 1.2108968098958333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> - </nestedChildShapes> - </classShape> - <classShape Id="8a79b099-7f87-4766-907a-db2c3e1b5716" absoluteBounds="3.5, 0.625, 2, 1.3862939453125005"> - <DataClassMoniker Name="/DataClassesDataContext/FavoriteSite" /> - <nestedChildShapes> - <elementListCompartment Id="eba736b9-f9ec-484b-8083-c77155a49e4e" absoluteBounds="3.515, 1.085, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> - </nestedChildShapes> - </classShape> - <classShape Id="f909becb-85b1-4fe6-bb16-3feb3e4fe3ee" absoluteBounds="0.5, 3.5, 2, 1.7708968098958327"> - <DataClassMoniker Name="/DataClassesDataContext/Client" /> - <nestedChildShapes> - <elementListCompartment Id="464308c4-d112-4448-b0c9-d9b82fb0ca4e" absoluteBounds="0.515, 3.96, 1.9700000000000002, 1.2108968098958333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> - </nestedChildShapes> - </classShape> - <classShape Id="895ebbc8-8352-4c04-9e53-b8e6c8302d36" absoluteBounds="3.5, 3.125, 2, 1.9631982421874996"> - <DataClassMoniker Name="/DataClassesDataContext/ClientAuthorization" /> - <nestedChildShapes> - <elementListCompartment Id="403126d0-3d2a-4af4-b0b8-c489a830bbd4" absoluteBounds="3.515, 3.585, 1.9700000000000002, 1.4031982421875" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> - </nestedChildShapes> - </classShape> - <associationConnector edgePoints="[(2.625 : 1.31814697265625); (3.5 : 1.31814697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed"> - <AssociationMoniker Name="/DataClassesDataContext/User/User_FavoriteSite" /> - <nodes> - <classShapeMoniker Id="696d2c69-040e-411d-9257-bb664b743834" /> - <classShapeMoniker Id="8a79b099-7f87-4766-907a-db2c3e1b5716" /> - </nodes> - </associationConnector> - <classShape Id="a63562a7-acf2-4ed9-9686-52a1ad85633e" absoluteBounds="1.375, 6.375, 2, 1.3862939453124996"> - <DataClassMoniker Name="/DataClassesDataContext/Nonce" /> - <nestedChildShapes> - <elementListCompartment Id="9e4514ef-bc7b-4179-88e6-05363bf6ee5e" absoluteBounds="1.39, 6.835, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> - </nestedChildShapes> - </classShape> - <associationConnector edgePoints="[(2.5 : 4.29409912109375); (3.5 : 4.29409912109375)]" fixedFrom="NotFixed" fixedTo="NotFixed"> - <AssociationMoniker Name="/DataClassesDataContext/Client/Client_ClientAuthorization" /> - <nodes> - <classShapeMoniker Id="f909becb-85b1-4fe6-bb16-3feb3e4fe3ee" /> - <classShapeMoniker Id="895ebbc8-8352-4c04-9e53-b8e6c8302d36" /> - </nodes> - </associationConnector> - <associationConnector edgePoints="[(2.59375 : 2.27089680989583); (2.59375 : 3.28125); (3.5 : 3.28125)]" fixedFrom="NotFixed" fixedTo="NotFixed"> - <AssociationMoniker Name="/DataClassesDataContext/User/User_ClientAuthorization" /> - <nodes> - <classShapeMoniker Id="696d2c69-040e-411d-9257-bb664b743834" /> - <classShapeMoniker Id="895ebbc8-8352-4c04-9e53-b8e6c8302d36" /> - </nodes> - </associationConnector> - </nestedChildShapes> -</ordesignerObjectsDiagram>
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/DataClasses.designer.cs b/samples/OAuthServiceProvider/Code/DataClasses.designer.cs deleted file mode 100644 index 0f70a2c..0000000 --- a/samples/OAuthServiceProvider/Code/DataClasses.designer.cs +++ /dev/null @@ -1,1046 +0,0 @@ -#pragma warning disable 1591 -//------------------------------------------------------------------------------ -// <auto-generated> -// This code was generated by a tool. -// Runtime Version:4.0.30319.1 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// </auto-generated> -//------------------------------------------------------------------------------ - -namespace OAuthServiceProvider.Code -{ - using System.Data.Linq; - using System.Data.Linq.Mapping; - using System.Data; - using System.Collections.Generic; - using System.Reflection; - using System.Linq; - using System.Linq.Expressions; - using System.ComponentModel; - using System; - - - [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="Database")] - public partial class DataClassesDataContext : System.Data.Linq.DataContext - { - - private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource(); - - #region Extensibility Method Definitions - partial void OnCreated(); - partial void InsertUser(User instance); - partial void UpdateUser(User instance); - partial void DeleteUser(User instance); - partial void InsertFavoriteSite(FavoriteSite instance); - partial void UpdateFavoriteSite(FavoriteSite instance); - partial void DeleteFavoriteSite(FavoriteSite instance); - partial void InsertClient(Client instance); - partial void UpdateClient(Client instance); - partial void DeleteClient(Client instance); - partial void InsertClientAuthorization(ClientAuthorization instance); - partial void UpdateClientAuthorization(ClientAuthorization instance); - partial void DeleteClientAuthorization(ClientAuthorization instance); - partial void InsertNonce(Nonce instance); - partial void UpdateNonce(Nonce instance); - partial void DeleteNonce(Nonce instance); - #endregion - - public DataClassesDataContext() : - base(global::System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString, mappingSource) - { - OnCreated(); - } - - public DataClassesDataContext(string connection) : - base(connection, mappingSource) - { - OnCreated(); - } - - public DataClassesDataContext(System.Data.IDbConnection connection) : - base(connection, mappingSource) - { - OnCreated(); - } - - public DataClassesDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : - base(connection, mappingSource) - { - OnCreated(); - } - - public DataClassesDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : - base(connection, mappingSource) - { - OnCreated(); - } - - public System.Data.Linq.Table<User> Users - { - get - { - return this.GetTable<User>(); - } - } - - public System.Data.Linq.Table<FavoriteSite> FavoriteSites - { - get - { - return this.GetTable<FavoriteSite>(); - } - } - - public System.Data.Linq.Table<Client> Clients - { - get - { - return this.GetTable<Client>(); - } - } - - public System.Data.Linq.Table<ClientAuthorization> ClientAuthorizations - { - get - { - return this.GetTable<ClientAuthorization>(); - } - } - - public System.Data.Linq.Table<Nonce> Nonces - { - get - { - return this.GetTable<Nonce>(); - } - } - } - - [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.[User]")] - public partial class User : INotifyPropertyChanging, INotifyPropertyChanged - { - - private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); - - private int _UserId; - - private string _OpenIDClaimedIdentifier; - - private string _OpenIDFriendlyIdentifier; - - private string _FullName; - - private System.Nullable<int> _Age; - - private EntitySet<FavoriteSite> _FavoriteSites; - - private EntitySet<ClientAuthorization> _OAuthTokens; - - #region Extensibility Method Definitions - partial void OnLoaded(); - partial void OnValidate(System.Data.Linq.ChangeAction action); - partial void OnCreated(); - partial void OnUserIdChanging(int value); - partial void OnUserIdChanged(); - partial void OnOpenIDClaimedIdentifierChanging(string value); - partial void OnOpenIDClaimedIdentifierChanged(); - partial void OnOpenIDFriendlyIdentifierChanging(string value); - partial void OnOpenIDFriendlyIdentifierChanged(); - partial void OnFullNameChanging(string value); - partial void OnFullNameChanged(); - partial void OnAgeChanging(System.Nullable<int> value); - partial void OnAgeChanged(); - #endregion - - public User() - { - this._FavoriteSites = new EntitySet<FavoriteSite>(new Action<FavoriteSite>(this.attach_FavoriteSites), new Action<FavoriteSite>(this.detach_FavoriteSites)); - this._OAuthTokens = new EntitySet<ClientAuthorization>(new Action<ClientAuthorization>(this.attach_OAuthTokens), new Action<ClientAuthorization>(this.detach_OAuthTokens)); - OnCreated(); - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] - public int UserId - { - get - { - return this._UserId; - } - set - { - if ((this._UserId != value)) - { - this.OnUserIdChanging(value); - this.SendPropertyChanging(); - this._UserId = value; - this.SendPropertyChanged("UserId"); - this.OnUserIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OpenIDClaimedIdentifier", DbType="NVarChar(150) NOT NULL", CanBeNull=false)] - public string OpenIDClaimedIdentifier - { - get - { - return this._OpenIDClaimedIdentifier; - } - set - { - if ((this._OpenIDClaimedIdentifier != value)) - { - this.OnOpenIDClaimedIdentifierChanging(value); - this.SendPropertyChanging(); - this._OpenIDClaimedIdentifier = value; - this.SendPropertyChanged("OpenIDClaimedIdentifier"); - this.OnOpenIDClaimedIdentifierChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OpenIDFriendlyIdentifier", DbType="NVarChar(150)")] - public string OpenIDFriendlyIdentifier - { - get - { - return this._OpenIDFriendlyIdentifier; - } - set - { - if ((this._OpenIDFriendlyIdentifier != value)) - { - this.OnOpenIDFriendlyIdentifierChanging(value); - this.SendPropertyChanging(); - this._OpenIDFriendlyIdentifier = value; - this.SendPropertyChanged("OpenIDFriendlyIdentifier"); - this.OnOpenIDFriendlyIdentifierChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FullName", DbType="NVarChar(150)", CanBeNull=false)] - public string FullName - { - get - { - return this._FullName; - } - set - { - if ((this._FullName != value)) - { - this.OnFullNameChanging(value); - this.SendPropertyChanging(); - this._FullName = value; - this.SendPropertyChanged("FullName"); - this.OnFullNameChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Age", DbType="int")] - public System.Nullable<int> Age - { - get - { - return this._Age; - } - set - { - if ((this._Age != value)) - { - this.OnAgeChanging(value); - this.SendPropertyChanging(); - this._Age = value; - this.SendPropertyChanged("Age"); - this.OnAgeChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.AssociationAttribute(Name="User_FavoriteSite", Storage="_FavoriteSites", ThisKey="UserId", OtherKey="UserId")] - public EntitySet<FavoriteSite> FavoriteSites - { - get - { - return this._FavoriteSites; - } - set - { - this._FavoriteSites.Assign(value); - } - } - - [global::System.Data.Linq.Mapping.AssociationAttribute(Name="User_ClientAuthorization", Storage="_OAuthTokens", ThisKey="UserId", OtherKey="UserId")] - public EntitySet<ClientAuthorization> ClientAuthorizations - { - get - { - return this._OAuthTokens; - } - set - { - this._OAuthTokens.Assign(value); - } - } - - public event PropertyChangingEventHandler PropertyChanging; - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void SendPropertyChanging() - { - if ((this.PropertyChanging != null)) - { - this.PropertyChanging(this, emptyChangingEventArgs); - } - } - - protected virtual void SendPropertyChanged(String propertyName) - { - if ((this.PropertyChanged != null)) - { - this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - - private void attach_FavoriteSites(FavoriteSite entity) - { - this.SendPropertyChanging(); - entity.User = this; - } - - private void detach_FavoriteSites(FavoriteSite entity) - { - this.SendPropertyChanging(); - entity.User = null; - } - - private void attach_OAuthTokens(ClientAuthorization entity) - { - this.SendPropertyChanging(); - entity.User = this; - } - - private void detach_OAuthTokens(ClientAuthorization entity) - { - this.SendPropertyChanging(); - entity.User = null; - } - } - - [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.FavoriteSite")] - public partial class FavoriteSite : INotifyPropertyChanging, INotifyPropertyChanged - { - - private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); - - private int _FavoriteSiteId; - - private int _UserId; - - private string _SiteUrl; - - private EntityRef<User> _User; - - #region Extensibility Method Definitions - partial void OnLoaded(); - partial void OnValidate(System.Data.Linq.ChangeAction action); - partial void OnCreated(); - partial void OnFavoriteSiteIdChanging(int value); - partial void OnFavoriteSiteIdChanged(); - partial void OnUserIdChanging(int value); - partial void OnUserIdChanged(); - partial void OnSiteUrlChanging(string value); - partial void OnSiteUrlChanged(); - #endregion - - public FavoriteSite() - { - this._User = default(EntityRef<User>); - OnCreated(); - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FavoriteSiteId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] - public int FavoriteSiteId - { - get - { - return this._FavoriteSiteId; - } - set - { - if ((this._FavoriteSiteId != value)) - { - this.OnFavoriteSiteIdChanging(value); - this.SendPropertyChanging(); - this._FavoriteSiteId = value; - this.SendPropertyChanged("FavoriteSiteId"); - this.OnFavoriteSiteIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="Int NOT NULL")] - public int UserId - { - get - { - return this._UserId; - } - set - { - if ((this._UserId != value)) - { - if (this._User.HasLoadedOrAssignedValue) - { - throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(); - } - this.OnUserIdChanging(value); - this.SendPropertyChanging(); - this._UserId = value; - this.SendPropertyChanged("UserId"); - this.OnUserIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_SiteUrl", DbType="NVarChar(255) NOT NULL", CanBeNull=false)] - public string SiteUrl - { - get - { - return this._SiteUrl; - } - set - { - if ((this._SiteUrl != value)) - { - this.OnSiteUrlChanging(value); - this.SendPropertyChanging(); - this._SiteUrl = value; - this.SendPropertyChanged("SiteUrl"); - this.OnSiteUrlChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.AssociationAttribute(Name="User_FavoriteSite", Storage="_User", ThisKey="UserId", OtherKey="UserId", IsForeignKey=true, DeleteOnNull=true, DeleteRule="CASCADE")] - public User User - { - get - { - return this._User.Entity; - } - set - { - User previousValue = this._User.Entity; - if (((previousValue != value) - || (this._User.HasLoadedOrAssignedValue == false))) - { - this.SendPropertyChanging(); - if ((previousValue != null)) - { - this._User.Entity = null; - previousValue.FavoriteSites.Remove(this); - } - this._User.Entity = value; - if ((value != null)) - { - value.FavoriteSites.Add(this); - this._UserId = value.UserId; - } - else - { - this._UserId = default(int); - } - this.SendPropertyChanged("User"); - } - } - } - - public event PropertyChangingEventHandler PropertyChanging; - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void SendPropertyChanging() - { - if ((this.PropertyChanging != null)) - { - this.PropertyChanging(this, emptyChangingEventArgs); - } - } - - protected virtual void SendPropertyChanged(String propertyName) - { - if ((this.PropertyChanged != null)) - { - this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - } - - [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Client")] - public partial class Client : INotifyPropertyChanging, INotifyPropertyChanged - { - - private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); - - private int _ClientId; - - private string _ClientIdentifier; - - private string _ClientSecret; - - private string _Callback; - - private string _Name; - - private EntitySet<ClientAuthorization> _OAuthTokens; - - #region Extensibility Method Definitions - partial void OnLoaded(); - partial void OnValidate(System.Data.Linq.ChangeAction action); - partial void OnCreated(); - partial void OnClientIdChanging(int value); - partial void OnClientIdChanged(); - partial void OnClientIdentifierChanging(string value); - partial void OnClientIdentifierChanged(); - partial void OnClientSecretChanging(string value); - partial void OnClientSecretChanged(); - partial void OnCallbackChanging(string value); - partial void OnCallbackChanged(); - partial void OnNameChanging(string value); - partial void OnNameChanged(); - #endregion - - public Client() - { - this._OAuthTokens = new EntitySet<ClientAuthorization>(new Action<ClientAuthorization>(this.attach_OAuthTokens), new Action<ClientAuthorization>(this.detach_OAuthTokens)); - OnCreated(); - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] - public int ClientId - { - get - { - return this._ClientId; - } - set - { - if ((this._ClientId != value)) - { - this.OnClientIdChanging(value); - this.SendPropertyChanging(); - this._ClientId = value; - this.SendPropertyChanged("ClientId"); - this.OnClientIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientIdentifier", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] - public string ClientIdentifier - { - get - { - return this._ClientIdentifier; - } - set - { - if ((this._ClientIdentifier != value)) - { - this.OnClientIdentifierChanging(value); - this.SendPropertyChanging(); - this._ClientIdentifier = value; - this.SendPropertyChanged("ClientIdentifier"); - this.OnClientIdentifierChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientSecret", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] - public string ClientSecret - { - get - { - return this._ClientSecret; - } - set - { - if ((this._ClientSecret != value)) - { - this.OnClientSecretChanging(value); - this.SendPropertyChanging(); - this._ClientSecret = value; - this.SendPropertyChanged("ClientSecret"); - this.OnClientSecretChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Callback")] - public string Callback - { - get - { - return this._Callback; - } - set - { - if ((this._Callback != value)) - { - this.OnCallbackChanging(value); - this.SendPropertyChanging(); - this._Callback = value; - this.SendPropertyChanged("Callback"); - this.OnCallbackChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", CanBeNull=false)] - public string Name - { - get - { - return this._Name; - } - set - { - if ((this._Name != value)) - { - this.OnNameChanging(value); - this.SendPropertyChanging(); - this._Name = value; - this.SendPropertyChanged("Name"); - this.OnNameChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Client_ClientAuthorization", Storage="_OAuthTokens", ThisKey="ClientId", OtherKey="ClientId")] - public EntitySet<ClientAuthorization> ClientAuthorizations - { - get - { - return this._OAuthTokens; - } - set - { - this._OAuthTokens.Assign(value); - } - } - - public event PropertyChangingEventHandler PropertyChanging; - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void SendPropertyChanging() - { - if ((this.PropertyChanging != null)) - { - this.PropertyChanging(this, emptyChangingEventArgs); - } - } - - protected virtual void SendPropertyChanged(String propertyName) - { - if ((this.PropertyChanged != null)) - { - this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - - private void attach_OAuthTokens(ClientAuthorization entity) - { - this.SendPropertyChanging(); - entity.Client = this; - } - - private void detach_OAuthTokens(ClientAuthorization entity) - { - this.SendPropertyChanging(); - entity.Client = null; - } - } - - [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.ClientAuthorization")] - public partial class ClientAuthorization : INotifyPropertyChanging, INotifyPropertyChanged - { - - private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); - - private int _AuthorizationId; - - private System.DateTime _IssueDate; - - private int _ClientId; - - private System.Nullable<int> _UserId; - - private string _Scope; - - private System.Nullable<System.DateTime> _ExpirationDateUtc; - - private EntityRef<Client> _Client; - - private EntityRef<User> _User; - - #region Extensibility Method Definitions - partial void OnLoaded(); - partial void OnValidate(System.Data.Linq.ChangeAction action); - partial void OnCreated(); - partial void OnAuthorizationIdChanging(int value); - partial void OnAuthorizationIdChanged(); - partial void OnCreatedOnUtcChanging(System.DateTime value); - partial void OnCreatedOnUtcChanged(); - partial void OnClientIdChanging(int value); - partial void OnClientIdChanged(); - partial void OnUserIdChanging(System.Nullable<int> value); - partial void OnUserIdChanged(); - partial void OnScopeChanging(string value); - partial void OnScopeChanged(); - partial void OnExpirationDateUtcChanging(System.Nullable<System.DateTime> value); - partial void OnExpirationDateUtcChanged(); - #endregion - - public ClientAuthorization() - { - this._Client = default(EntityRef<Client>); - this._User = default(EntityRef<User>); - OnCreated(); - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AuthorizationId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] - public int AuthorizationId - { - get - { - return this._AuthorizationId; - } - set - { - if ((this._AuthorizationId != value)) - { - this.OnAuthorizationIdChanging(value); - this.SendPropertyChanging(); - this._AuthorizationId = value; - this.SendPropertyChanged("AuthorizationId"); - this.OnAuthorizationIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IssueDate", DbType="DateTime NOT NULL")] - public System.DateTime CreatedOnUtc - { - get - { - return this._IssueDate; - } - set - { - if ((this._IssueDate != value)) - { - this.OnCreatedOnUtcChanging(value); - this.SendPropertyChanging(); - this._IssueDate = value; - this.SendPropertyChanged("CreatedOnUtc"); - this.OnCreatedOnUtcChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientId", DbType="Int NOT NULL")] - public int ClientId - { - get - { - return this._ClientId; - } - set - { - if ((this._ClientId != value)) - { - if (this._Client.HasLoadedOrAssignedValue) - { - throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(); - } - this.OnClientIdChanging(value); - this.SendPropertyChanging(); - this._ClientId = value; - this.SendPropertyChanged("ClientId"); - this.OnClientIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="Int")] - public System.Nullable<int> UserId - { - get - { - return this._UserId; - } - set - { - if ((this._UserId != value)) - { - if (this._User.HasLoadedOrAssignedValue) - { - throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(); - } - this.OnUserIdChanging(value); - this.SendPropertyChanging(); - this._UserId = value; - this.SendPropertyChanged("UserId"); - this.OnUserIdChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Scope", DbType="nvarchar(MAX)", CanBeNull=false)] - public string Scope - { - get - { - return this._Scope; - } - set - { - if ((this._Scope != value)) - { - this.OnScopeChanging(value); - this.SendPropertyChanging(); - this._Scope = value; - this.SendPropertyChanged("Scope"); - this.OnScopeChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ExpirationDateUtc", DbType="DateTime NULL")] - public System.Nullable<System.DateTime> ExpirationDateUtc - { - get - { - return this._ExpirationDateUtc; - } - set - { - if ((this._ExpirationDateUtc != value)) - { - this.OnExpirationDateUtcChanging(value); - this.SendPropertyChanging(); - this._ExpirationDateUtc = value; - this.SendPropertyChanged("ExpirationDateUtc"); - this.OnExpirationDateUtcChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Client_ClientAuthorization", Storage="_Client", ThisKey="ClientId", OtherKey="ClientId", IsForeignKey=true, DeleteOnNull=true, DeleteRule="CASCADE")] - public Client Client - { - get - { - return this._Client.Entity; - } - set - { - Client previousValue = this._Client.Entity; - if (((previousValue != value) - || (this._Client.HasLoadedOrAssignedValue == false))) - { - this.SendPropertyChanging(); - if ((previousValue != null)) - { - this._Client.Entity = null; - previousValue.ClientAuthorizations.Remove(this); - } - this._Client.Entity = value; - if ((value != null)) - { - value.ClientAuthorizations.Add(this); - this._ClientId = value.ClientId; - } - else - { - this._ClientId = default(int); - } - this.SendPropertyChanged("Client"); - } - } - } - - [global::System.Data.Linq.Mapping.AssociationAttribute(Name="User_ClientAuthorization", Storage="_User", ThisKey="UserId", OtherKey="UserId", IsForeignKey=true, DeleteRule="CASCADE")] - public User User - { - get - { - return this._User.Entity; - } - set - { - User previousValue = this._User.Entity; - if (((previousValue != value) - || (this._User.HasLoadedOrAssignedValue == false))) - { - this.SendPropertyChanging(); - if ((previousValue != null)) - { - this._User.Entity = null; - previousValue.ClientAuthorizations.Remove(this); - } - this._User.Entity = value; - if ((value != null)) - { - value.ClientAuthorizations.Add(this); - this._UserId = value.UserId; - } - else - { - this._UserId = default(Nullable<int>); - } - this.SendPropertyChanged("User"); - } - } - } - - public event PropertyChangingEventHandler PropertyChanging; - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void SendPropertyChanging() - { - if ((this.PropertyChanging != null)) - { - this.PropertyChanging(this, emptyChangingEventArgs); - } - } - - protected virtual void SendPropertyChanged(String propertyName) - { - if ((this.PropertyChanged != null)) - { - this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - } - - [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Nonce")] - public partial class Nonce : INotifyPropertyChanging, INotifyPropertyChanged - { - - private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); - - private string _Context; - - private string _Code; - - private System.DateTime _Timestamp; - - #region Extensibility Method Definitions - partial void OnLoaded(); - partial void OnValidate(System.Data.Linq.ChangeAction action); - partial void OnCreated(); - partial void OnContextChanging(string value); - partial void OnContextChanged(); - partial void OnCodeChanging(string value); - partial void OnCodeChanged(); - partial void OnTimestampChanging(System.DateTime value); - partial void OnTimestampChanged(); - #endregion - - public Nonce() - { - OnCreated(); - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Context", CanBeNull=false, IsPrimaryKey=true)] - public string Context - { - get - { - return this._Context; - } - set - { - if ((this._Context != value)) - { - this.OnContextChanging(value); - this.SendPropertyChanging(); - this._Context = value; - this.SendPropertyChanged("Context"); - this.OnContextChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Code", CanBeNull=false, IsPrimaryKey=true)] - public string Code - { - get - { - return this._Code; - } - set - { - if ((this._Code != value)) - { - this.OnCodeChanging(value); - this.SendPropertyChanging(); - this._Code = value; - this.SendPropertyChanged("Code"); - this.OnCodeChanged(); - } - } - } - - [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Timestamp", IsPrimaryKey=true)] - public System.DateTime Timestamp - { - get - { - return this._Timestamp; - } - set - { - if ((this._Timestamp != value)) - { - this.OnTimestampChanging(value); - this.SendPropertyChanging(); - this._Timestamp = value; - this.SendPropertyChanged("Timestamp"); - this.OnTimestampChanged(); - } - } - } - - public event PropertyChangingEventHandler PropertyChanging; - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void SendPropertyChanging() - { - if ((this.PropertyChanging != null)) - { - this.PropertyChanging(this, emptyChangingEventArgs); - } - } - - protected virtual void SendPropertyChanged(String propertyName) - { - if ((this.PropertyChanged != null)) - { - this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - } -} -#pragma warning restore 1591 diff --git a/samples/OAuthServiceProvider/Code/DatabaseNonceStore.cs b/samples/OAuthServiceProvider/Code/DatabaseNonceStore.cs deleted file mode 100644 index 7c37a25..0000000 --- a/samples/OAuthServiceProvider/Code/DatabaseNonceStore.cs +++ /dev/null @@ -1,55 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Data.SqlClient; - using DotNetOpenAuth.Messaging.Bindings; - - /// <summary> - /// A database-persisted nonce store. - /// </summary> - public class DatabaseNonceStore : INonceStore { - /// <summary> - /// Initializes a new instance of the <see cref="DatabaseNonceStore"/> class. - /// </summary> - public DatabaseNonceStore() { - } - - #region INonceStore Members - - /// <summary> - /// Stores a given nonce and timestamp. - /// </summary> - /// <param name="context">The context, or namespace, within which the - /// <paramref name="nonce"/> must be unique. - /// The context SHOULD be treated as case-sensitive. - /// The value will never be <c>null</c> but may be the empty string.</param> - /// <param name="nonce">A series of random characters.</param> - /// <param name="timestampUtc">The UTC timestamp that together with the nonce string make it unique - /// within the given <paramref name="context"/>. - /// The timestamp may also be used by the data store to clear out old nonces.</param> - /// <returns> - /// True if the context+nonce+timestamp (combination) was not previously in the database. - /// False if the nonce was stored previously with the same timestamp and context. - /// </returns> - /// <remarks> - /// The nonce must be stored for no less than the maximum time window a message may - /// be processed within before being discarded as an expired message. - /// This maximum message age can be looked up via the - /// <see cref="DotNetOpenAuth.Configuration.MessagingElement.MaximumMessageLifetime"/> - /// property, accessible via the <see cref="DotNetOpenAuth.Configuration.DotNetOpenAuthSection.Configuration"/> - /// property. - /// </remarks> - public bool StoreNonce(string context, string nonce, DateTime timestampUtc) { - Global.DataContext.Nonces.InsertOnSubmit(new Nonce { Context = context, Code = nonce, Timestamp = timestampUtc }); - try { - Global.DataContext.SubmitChanges(); - return true; - } catch (System.Data.Linq.DuplicateKeyException) { - return false; - } catch (SqlException) { - return false; - } - } - - #endregion - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/Global.cs b/samples/OAuthServiceProvider/Code/Global.cs deleted file mode 100644 index 580cbf4..0000000 --- a/samples/OAuthServiceProvider/Code/Global.cs +++ /dev/null @@ -1,111 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Linq; - using System.ServiceModel; - using System.Text; - using System.Web; - using DotNetOpenAuth.OAuth2; - using DotNetOpenAuth.OAuth2.Messages; - - /// <summary> - /// The web application global events and properties. - /// </summary> - public class Global : HttpApplication { - /// <summary> - /// An application memory cache of recent log messages. - /// </summary> - public static StringBuilder LogMessages = new StringBuilder(); - - /// <summary> - /// The logger for this sample to use. - /// </summary> - public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.OAuthServiceProvider"); - - public static AuthorizationServer AuthorizationServer = new AuthorizationServer(new OAuth2AuthorizationServer()); - - /// <summary> - /// Gets the transaction-protected database connection for the current request. - /// </summary> - public static DataClassesDataContext DataContext { - get { - DataClassesDataContext dataContext = dataContextSimple; - if (dataContext == null) { - dataContext = new DataClassesDataContext(); - dataContext.Connection.Open(); - dataContext.Transaction = dataContext.Connection.BeginTransaction(); - dataContextSimple = dataContext; - } - - return dataContext; - } - } - - public static DatabaseNonceStore NonceStore { get; set; } - - public static User LoggedInUser { - get { return Global.DataContext.Users.SingleOrDefault(user => user.OpenIDClaimedIdentifier == HttpContext.Current.User.Identity.Name); } - } - - private static DataClassesDataContext dataContextSimple { - get { - if (HttpContext.Current != null) { - return HttpContext.Current.Items["DataContext"] as DataClassesDataContext; - } else if (OperationContext.Current != null) { - object data; - if (OperationContext.Current.IncomingMessageProperties.TryGetValue("DataContext", out data)) { - return data as DataClassesDataContext; - } else { - return null; - } - } else { - throw new InvalidOperationException(); - } - } - - set { - if (HttpContext.Current != null) { - HttpContext.Current.Items["DataContext"] = value; - } else if (OperationContext.Current != null) { - OperationContext.Current.IncomingMessageProperties["DataContext"] = value; - } else { - throw new InvalidOperationException(); - } - } - } - - private static void CommitAndCloseDatabaseIfNecessary() { - var dataContext = dataContextSimple; - if (dataContext != null) { - dataContext.SubmitChanges(); - dataContext.Transaction.Commit(); - dataContext.Connection.Close(); - } - } - - private void Application_Start(object sender, EventArgs e) { - log4net.Config.XmlConfigurator.Configure(); - Logger.Info("Sample starting..."); - string appPath = HttpContext.Current.Request.ApplicationPath; - if (!appPath.EndsWith("/")) { - appPath += "/"; - } - - Global.NonceStore = new DatabaseNonceStore(); - } - - private void Application_End(object sender, EventArgs e) { - Logger.Info("Sample shutting down..."); - - // this would be automatic, but in partial trust scenarios it is not. - log4net.LogManager.Shutdown(); - } - - private void Application_Error(object sender, EventArgs e) { - Logger.Error("An unhandled exception occurred in ASP.NET processing: " + Server.GetLastError(), Server.GetLastError()); - } - - private void Application_EndRequest(object sender, EventArgs e) { - CommitAndCloseDatabaseIfNecessary(); - } - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/IDataApi.cs b/samples/OAuthServiceProvider/Code/IDataApi.cs deleted file mode 100644 index 45853cd..0000000 --- a/samples/OAuthServiceProvider/Code/IDataApi.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Runtime.Serialization; - using System.ServiceModel; - using System.Text; - - [ServiceContract] - public interface IDataApi { - [OperationContract] - int? GetAge(); - - [OperationContract] - string GetName(); - - [OperationContract] - string[] GetFavoriteSites(); - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/OAuth2AuthorizationServer.cs b/samples/OAuthServiceProvider/Code/OAuth2AuthorizationServer.cs deleted file mode 100644 index ff87267..0000000 --- a/samples/OAuthServiceProvider/Code/OAuth2AuthorizationServer.cs +++ /dev/null @@ -1,109 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Security.Cryptography; - using System.Web; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.Messaging.Bindings; - using DotNetOpenAuth.OAuth2; - using DotNetOpenAuth.OAuth2.ChannelElements; - using DotNetOpenAuth.OAuth2.Messages; - - internal class OAuth2AuthorizationServer : IAuthorizationServer { - internal static readonly RSAParameters AsymmetricKey; - - private static readonly byte[] secret; - - private readonly INonceStore nonceStore = new DatabaseNonceStore(); - - static OAuth2AuthorizationServer() { - // For this sample, we just generate random secrets. - RandomNumberGenerator crypto = new RNGCryptoServiceProvider(); - secret = new byte[16]; - crypto.GetBytes(secret); - - AsymmetricKey = new RSACryptoServiceProvider().ExportParameters(true); - } - - #region Implementation of IAuthorizationServer - - public byte[] Secret { - get { return secret; } - } - - public INonceStore VerificationCodeNonceStore { - get { return this.nonceStore; } - } - - public RSAParameters AccessTokenSigningPrivateKey { - get { return AsymmetricKey; } - } - - public IConsumerDescription GetClient(string clientIdentifier) { - var consumerRow = Global.DataContext.Clients.SingleOrDefault( - consumerCandidate => consumerCandidate.ClientIdentifier == clientIdentifier); - if (consumerRow == null) { - throw new ArgumentOutOfRangeException("clientIdentifier"); - } - - return consumerRow; - } - - #endregion - - public bool IsAuthorizationValid(IAuthorizationDescription authorization) { - return this.IsAuthorizationValid(authorization.Scope, authorization.ClientIdentifier, authorization.UtcIssued, authorization.User); - } - - public bool CanBeAutoApproved(EndUserAuthorizationRequest authorizationRequest) { - if (authorizationRequest == null) { - throw new ArgumentNullException("authorizationRequest"); - } - - // NEVER issue an auto-approval to a client that would end up getting an access token immediately - // (without a client secret), as that would allow ANY client to spoof an approved client's identity - // and obtain unauthorized access to user data. - if (authorizationRequest.ResponseType == EndUserAuthorizationResponseType.AuthorizationCode) { - // Never issue auto-approval if the client secret is blank, since that too makes it easy to spoof - // a client's identity and obtain unauthorized access. - var requestingClient = Global.DataContext.Clients.First(c => c.ClientIdentifier == authorizationRequest.ClientIdentifier); - if (!string.IsNullOrEmpty(requestingClient.ClientSecret)) { - return this.IsAuthorizationValid( - authorizationRequest.Scope, - authorizationRequest.ClientIdentifier, - DateTime.UtcNow, - HttpContext.Current.User.Identity.Name); - } - } - - // Default to not auto-approving. - return false; - } - - private bool IsAuthorizationValid(HashSet<string> requestedScopes, string clientIdentifier, DateTime issuedUtc, string username) { - var grantedScopeStrings = from auth in Global.DataContext.ClientAuthorizations - where - auth.Client.ClientIdentifier == clientIdentifier && - auth.CreatedOnUtc <= issuedUtc && - (!auth.ExpirationDateUtc.HasValue || auth.ExpirationDateUtc.Value >= DateTime.UtcNow) && - auth.User.OpenIDClaimedIdentifier == username - select auth.Scope; - - if (!grantedScopeStrings.Any()) { - // No granted authorizations prior to the issuance of this token, so it must have been revoked. - // Even if later authorizations restore this client's ability to call in, we can't allow - // access tokens issued before the re-authorization because the revoked authorization should - // effectively and permanently revoke all access and refresh tokens. - return false; - } - - var grantedScopes = new HashSet<string>(OAuthUtilities.ScopeStringComparer); - foreach (string scope in grantedScopeStrings) { - grantedScopes.UnionWith(OAuthUtilities.SplitScopes(scope)); - } - - return requestedScopes.IsSubsetOf(grantedScopes); - } - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs b/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs deleted file mode 100644 index aa5428f..0000000 --- a/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.IdentityModel.Policy; - using System.Linq; - using System.Security.Principal; - using System.ServiceModel; - using System.ServiceModel.Channels; - using System.ServiceModel.Security; - - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.OAuth2; - - using ProtocolException = System.ServiceModel.ProtocolException; - - /// <summary> - /// A WCF extension to authenticate incoming messages using OAuth. - /// </summary> - public class OAuthAuthorizationManager : ServiceAuthorizationManager { - public OAuthAuthorizationManager() { - } - - protected override bool CheckAccessCore(OperationContext operationContext) { - if (!base.CheckAccessCore(operationContext)) { - return false; - } - - var httpDetails = operationContext.RequestContext.RequestMessage.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; - var requestUri = operationContext.RequestContext.RequestMessage.Properties["OriginalHttpRequestUri"] as Uri; - - try { - var principal = VerifyOAuth2(httpDetails, requestUri); - if (principal != null) { - var policy = new OAuthPrincipalAuthorizationPolicy(principal); - var policies = new List<IAuthorizationPolicy> { - policy, - }; - - var securityContext = new ServiceSecurityContext(policies.AsReadOnly()); - if (operationContext.IncomingMessageProperties.Security != null) { - operationContext.IncomingMessageProperties.Security.ServiceSecurityContext = securityContext; - } else { - operationContext.IncomingMessageProperties.Security = new SecurityMessageProperty { - ServiceSecurityContext = securityContext, - }; - } - - securityContext.AuthorizationContext.Properties["Identities"] = new List<IIdentity> { - principal.Identity, - }; - - // Only allow this method call if the access token scope permits it. - return principal.IsInRole(operationContext.IncomingMessageHeaders.Action); - } else { - return false; - } - } catch (ProtocolException ex) { - Global.Logger.Error("Error processing OAuth messages.", ex); - } - - return false; - } - - private static IPrincipal VerifyOAuth2(HttpRequestMessageProperty httpDetails, Uri requestUri) { - // for this sample where the auth server and resource server are the same site, - // we use the same public/private key. - var resourceServer = new ResourceServer( - new StandardAccessTokenAnalyzer( - OAuth2AuthorizationServer.AsymmetricKey, - OAuth2AuthorizationServer.AsymmetricKey)); - - IPrincipal result; - var error = resourceServer.VerifyAccess(new HttpRequestInfo(httpDetails, requestUri), out result); - - // TODO: return the prepared error code. - return error != null ? null : result; - } - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/OAuthPrincipalAuthorizationPolicy.cs b/samples/OAuthServiceProvider/Code/OAuthPrincipalAuthorizationPolicy.cs deleted file mode 100644 index cf14eab..0000000 --- a/samples/OAuthServiceProvider/Code/OAuthPrincipalAuthorizationPolicy.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.IdentityModel.Claims; - using System.IdentityModel.Policy; - using System.Linq; - using System.Security.Principal; - using System.Web; - - public class OAuthPrincipalAuthorizationPolicy : IAuthorizationPolicy { - private readonly Guid uniqueId = Guid.NewGuid(); - private readonly IPrincipal principal; - - /// <summary> - /// Initializes a new instance of the <see cref="OAuthPrincipalAuthorizationPolicy"/> class. - /// </summary> - /// <param name="principal">The principal.</param> - public OAuthPrincipalAuthorizationPolicy(IPrincipal principal) { - this.principal = principal; - } - - #region IAuthorizationComponent Members - - /// <summary> - /// Gets a unique ID for this instance. - /// </summary> - public string Id { - get { return this.uniqueId.ToString(); } - } - - #endregion - - #region IAuthorizationPolicy Members - - public ClaimSet Issuer { - get { return ClaimSet.System; } - } - - public bool Evaluate(EvaluationContext evaluationContext, ref object state) { - evaluationContext.AddClaimSet(this, new DefaultClaimSet(Claim.CreateNameClaim(this.principal.Identity.Name))); - evaluationContext.Properties["Principal"] = this.principal; - return true; - } - - #endregion - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/TracePageAppender.cs b/samples/OAuthServiceProvider/Code/TracePageAppender.cs deleted file mode 100644 index 8f97c89..0000000 --- a/samples/OAuthServiceProvider/Code/TracePageAppender.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.IO; - using System.Web; - - public class TracePageAppender : log4net.Appender.AppenderSkeleton { - protected override void Append(log4net.Core.LoggingEvent loggingEvent) { - StringWriter sw = new StringWriter(Global.LogMessages); - Layout.Format(sw, loggingEvent); - } - } -}
\ No newline at end of file diff --git a/samples/OAuthServiceProvider/Code/Utilities.cs b/samples/OAuthServiceProvider/Code/Utilities.cs deleted file mode 100644 index a225650..0000000 --- a/samples/OAuthServiceProvider/Code/Utilities.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace OAuthServiceProvider.Code { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Security.Principal; - using System.Web; - - /// <summary> - /// Extension methods and other helpful utility methods. - /// </summary> - public static class Utilities { - /// <summary> - /// Gets the database entity representing the user identified by a given <see cref="IIdentity"/> instance. - /// </summary> - /// <param name="identity">The identity of the user.</param> - /// <returns> - /// The database object for that user; or <c>null</c> if the user could not - /// be found or if <paramref name="identity"/> is <c>null</c> or represents an anonymous identity. - /// </returns> - public static User GetUser(this IIdentity identity) { - if (identity == null || !identity.IsAuthenticated) { - return null; - } - - return Global.DataContext.Users.SingleOrDefault(user => user.OpenIDClaimedIdentifier == identity.Name); - } - } -}
\ No newline at end of file |