diff options
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock')
6 files changed, 201 insertions, 7 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj index 5a3e532..aac67d4 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj +++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj @@ -73,6 +73,8 @@ <Reference Include="System.Core"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> + <Reference Include="System.Runtime.Serialization" /> + <Reference Include="System.ServiceModel.Web" /> <Reference Include="System.Web" /> <Reference Include="System.Xml.Linq"> <RequiredTargetFramework>3.5</RequiredTargetFramework> @@ -87,24 +89,22 @@ <Compile Include="CustomExtensions\Acme.cs" /> <Compile Include="CustomExtensions\AcmeRequest.cs" /> <Compile Include="CustomExtensions\AcmeResponse.cs" /> + <Compile Include="Facebook\FacebookClient.cs" /> + <Compile Include="Facebook\FacebookGraph.cs" /> <Compile Include="CustomExtensions\UIRequestAtRelyingPartyFactory.cs" /> <Compile Include="GoogleConsumer.cs" /> + <Compile Include="InMemoryClientAuthorizationTracker.cs" /> <Compile Include="InMemoryTokenManager.cs"> <SubType>Code</SubType> </Compile> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="TokenManager.cs" /> <Compile Include="TwitterConsumer.cs" /> <Compile Include="Util.cs" /> <Compile Include="YammerConsumer.cs" /> <Compile Include="YubikeyRelyingParty.cs" /> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\..\src\DotNetOpenAuth\DotNetOpenAuth.csproj"> - <Project>{3191B653-F76D-4C1A-9A5A-347BC3AAAAB7}</Project> - <Name>DotNetOpenAuth</Name> - </ProjectReference> - </ItemGroup> - <ItemGroup> <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <Visible>False</Visible> <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> @@ -121,6 +121,48 @@ <Install>true</Install> </BootstrapperPackage> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\src\DotNetOpenAuth.InfoCard\DotNetOpenAuth.InfoCard.csproj"> + <Project>{408D10B8-34BA-4CBD-B7AA-FEB1907ABA4C}</Project> + <Name>DotNetOpenAuth.InfoCard</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.Core\DotNetOpenAuth.Core.csproj"> + <Project>{60426312-6AE5-4835-8667-37EDEA670222}</Project> + <Name>DotNetOpenAuth.Core</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth.Consumer\DotNetOpenAuth.OAuth.Consumer.csproj"> + <Project>{B202E40D-4663-4A2B-ACDA-865F88FF7CAA}</Project> + <Name>DotNetOpenAuth.OAuth.Consumer</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth2.Client.UI\DotNetOpenAuth.OAuth2.Client.UI.csproj"> + <Project>{ADC2CC8C-541E-4F86-ACB1-DD504A36FA4B}</Project> + <Name>DotNetOpenAuth.OAuth2.Client.UI</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth2.Client\DotNetOpenAuth.OAuth2.Client.csproj"> + <Project>{CDEDD439-7F35-4E6E-8605-4E70BDC4CC99}</Project> + <Name>DotNetOpenAuth.OAuth2.Client</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth2\DotNetOpenAuth.OAuth2.csproj"> + <Project>{56459A6C-6BA2-4BAC-A9C0-27E3BD961FA6}</Project> + <Name>DotNetOpenAuth.OAuth2</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OAuth\DotNetOpenAuth.OAuth.csproj"> + <Project>{A288FCC8-6FCF-46DA-A45E-5F9281556361}</Project> + <Name>DotNetOpenAuth.OAuth</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OpenId.Provider\DotNetOpenAuth.OpenId.Provider.csproj"> + <Project>{F8284738-3B5D-4733-A511-38C23F4A763F}</Project> + <Name>DotNetOpenAuth.OpenId.Provider</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OpenId.RelyingParty\DotNetOpenAuth.OpenId.RelyingParty.csproj"> + <Project>{F458AB60-BA1C-43D9-8CEF-EC01B50BE87B}</Project> + <Name>DotNetOpenAuth.OpenId.RelyingParty</Name> + </ProjectReference> + <ProjectReference Include="..\..\src\DotNetOpenAuth.OpenId\DotNetOpenAuth.OpenId.csproj"> + <Project>{3896A32A-E876-4C23-B9B8-78E17D134CD3}</Project> + <Name>DotNetOpenAuth.OpenId</Name> + </ProjectReference> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " /> </Project>
\ No newline at end of file diff --git a/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookClient.cs b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookClient.cs new file mode 100644 index 0000000..f838962 --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookClient.cs @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------- +// <copyright file="FacebookClient.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Web; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuth2; + + public class FacebookClient : WebServerClient { + private static readonly AuthorizationServerDescription FacebookDescription = new AuthorizationServerDescription { + TokenEndpoint = new Uri("https://graph.facebook.com/oauth/access_token"), + AuthorizationEndpoint = new Uri("https://graph.facebook.com/oauth/authorize"), + }; + + /// <summary> + /// Initializes a new instance of the <see cref="FacebookClient"/> class. + /// </summary> + public FacebookClient() : base(FacebookDescription) { + this.AuthorizationTracker = new TokenManager(); + } + } +} diff --git a/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs new file mode 100644 index 0000000..02d3f3c --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs @@ -0,0 +1,54 @@ +//----------------------------------------------------------------------- +// <copyright file="FacebookGraph.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock.Facebook { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Runtime.Serialization; + using System.Runtime.Serialization.Json; + using System.Text; + + [DataContract] + public class FacebookGraph { + private static DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(FacebookGraph)); + + [DataMember(Name = "id")] + public long Id { get; set; } + + [DataMember(Name = "name")] + public string Name { get; set; } + + [DataMember(Name = "first_name")] + public string FirstName { get; set; } + + [DataMember(Name = "last_name")] + public string LastName { get; set; } + + [DataMember(Name = "link")] + public Uri Link { get; set; } + + [DataMember(Name = "birthday")] + public string Birthday { get; set; } + + public static FacebookGraph Deserialize(string json) { + if (String.IsNullOrEmpty(json)) { + throw new ArgumentNullException("json"); + } + + return Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json))); + } + + public static FacebookGraph Deserialize(Stream jsonStream) { + if (jsonStream == null) { + throw new ArgumentNullException("jsonStream"); + } + + return (FacebookGraph)jsonSerializer.ReadObject(jsonStream); + } + } +} diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs index 474a569..7be629e 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs +++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs @@ -163,7 +163,7 @@ namespace DotNetOpenAuth.ApplicationBlock { RequestTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest), UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthAuthorizeToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest), AccessTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetAccessToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest), - TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new RsaSha1SigningBindingElement(signingCertificate) }, + TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new RsaSha1ConsumerSigningBindingElement(signingCertificate) }, }; } diff --git a/samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs b/samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs new file mode 100644 index 0000000..ef3b686 --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------- +// <copyright file="InMemoryClientAuthorizationTracker.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.ServiceModel; + using System.Text; + using System.Threading; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuth2; + +#if SAMPLESONLY + internal class InMemoryClientAuthorizationTracker : IClientAuthorizationTracker { + private readonly Dictionary<int, IAuthorizationState> savedStates = new Dictionary<int, IAuthorizationState>(); + private int stateCounter; + + #region Implementation of IClientTokenManager + + /// <summary> + /// Gets the state of the authorization for a given callback URL and client state. + /// </summary> + /// <param name="callbackUrl">The callback URL.</param> + /// <param name="clientState">State of the client stored at the beginning of an authorization request.</param> + /// <returns>The authorization state; may be <c>null</c> if no authorization state matches.</returns> + public IAuthorizationState GetAuthorizationState(Uri callbackUrl, string clientState) { + IAuthorizationState state; + if (this.savedStates.TryGetValue(int.Parse(clientState), out state)) { + if (state.Callback != callbackUrl) { + throw new DotNetOpenAuth.Messaging.ProtocolException("Client state and callback URL do not match."); + } + } + + return state; + } + + #endregion + + internal IAuthorizationState NewAuthorization(HashSet<string> scope, out string clientState) { + int counter = Interlocked.Increment(ref this.stateCounter); + clientState = counter.ToString(CultureInfo.InvariantCulture); + return this.savedStates[counter] = new AuthorizationState(scope); + } + } +#endif +} diff --git a/samples/DotNetOpenAuth.ApplicationBlock/TokenManager.cs b/samples/DotNetOpenAuth.ApplicationBlock/TokenManager.cs new file mode 100644 index 0000000..50ff85b --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/TokenManager.cs @@ -0,0 +1,18 @@ +//----------------------------------------------------------------------- +// <copyright file="TokenManager.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock { + using System; + using DotNetOpenAuth.OAuth2; + + public class TokenManager : IClientAuthorizationTracker { + public IAuthorizationState GetAuthorizationState(Uri callbackUrl, string clientState) { + return new AuthorizationState { + Callback = callbackUrl, + }; + } + } +} |