summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-06-17 23:35:51 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-06-17 23:35:51 -0700
commit1cfef2932368360a450e963f9e83c32cfd112f55 (patch)
tree4fb0c5a68ff6cd7af3c25d3156f0aaed266924fb /samples/DotNetOpenAuth.ApplicationBlock
parent5fcb636cd7485ccc1c19e36ddb212577ac0c7b43 (diff)
downloadDotNetOpenAuth-1cfef2932368360a450e963f9e83c32cfd112f55.zip
DotNetOpenAuth-1cfef2932368360a450e963f9e83c32cfd112f55.tar.gz
DotNetOpenAuth-1cfef2932368360a450e963f9e83c32cfd112f55.tar.bz2
Added sample Yammer OAuth 1.0 consumer.
Yammer has a troublesome non-standard implementation of OAuth SP.
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj1
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs61
2 files changed, 62 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
index 6739bf9..8a580e6 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
+++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
@@ -93,6 +93,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TwitterConsumer.cs" />
<Compile Include="Util.cs" />
+ <Compile Include="YammerConsumer.cs" />
<Compile Include="YubikeyRelyingParty.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs
new file mode 100644
index 0000000..3824861
--- /dev/null
+++ b/samples/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs
@@ -0,0 +1,61 @@
+//-----------------------------------------------------------------------
+// <copyright file="YammerConsumer.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.Net;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuth;
+ using DotNetOpenAuth.OAuth.ChannelElements;
+ using DotNetOpenAuth.OAuth.Messages;
+
+ public static class YammerConsumer {
+ /// <summary>
+ /// The Consumer to use for accessing Google data APIs.
+ /// </summary>
+ public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription {
+ RequestTokenEndpoint = new MessageReceivingEndpoint("https://www.yammer.com/oauth/request_token", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest),
+ UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://www.yammer.com/oauth/authorize", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
+ AccessTokenEndpoint = new MessageReceivingEndpoint("https://www.yammer.com/oauth/access_token", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest),
+ TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new PlaintextSigningBindingElement() },
+ ProtocolVersion = ProtocolVersion.V10,
+ };
+
+ public static DesktopConsumer CreateConsumer(IConsumerTokenManager tokenManager) {
+ return new DesktopConsumer(ServiceDescription, tokenManager);
+ }
+
+ public static Uri PrepareRequestAuthorization(DesktopConsumer consumer, out string requestToken) {
+ if (consumer == null) {
+ throw new ArgumentNullException("consumer");
+ }
+
+ Uri authorizationUrl = consumer.RequestUserAuthorization(null, null, out requestToken);
+ return authorizationUrl;
+ }
+
+ public static AuthorizedTokenResponse CompleteAuthorization(DesktopConsumer consumer, string requestToken, string userCode) {
+ // Because Yammer has a proprietary callback_token parameter, and it's passed
+ // with the message that specifically bans extra arguments being passed, we have
+ // to cheat by adding the data to the URL itself here.
+ var customServiceDescription = new ServiceProviderDescription {
+ RequestTokenEndpoint = ServiceDescription.RequestTokenEndpoint,
+ UserAuthorizationEndpoint = ServiceDescription.UserAuthorizationEndpoint,
+ AccessTokenEndpoint = new MessageReceivingEndpoint(ServiceDescription.AccessTokenEndpoint.Location.AbsoluteUri + "?callback_token=" + Uri.EscapeDataString(userCode), HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest),
+ TamperProtectionElements = ServiceDescription.TamperProtectionElements,
+ ProtocolVersion = ProtocolVersion.V10,
+ };
+
+ // To use a custom service description we also must create a new WebConsumer.
+ var customConsumer = new DesktopConsumer(customServiceDescription, consumer.TokenManager);
+ var response = customConsumer.ProcessUserAuthorization(requestToken);
+ return response;
+ }
+ }
+}