summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs
diff options
context:
space:
mode:
authorDavid Christiansen <coding@davedoes.net>2012-06-30 16:06:46 -0700
committerDavid Christiansen <coding@davedoes.net>2012-06-30 16:06:46 -0700
commit06401bb049dc29cf4446eb61a4a72317a644ce54 (patch)
tree7c475929350b31b4b848a1faa57bd0d7cbbf512c /src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs
parent02ce959db12fec57e846e5ebfa662cd0327ce69c (diff)
parent3286c37f3a967e7d142534df84604a66be9d176c (diff)
downloadDotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.zip
DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.gz
DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.bz2
Merge pull request #1 from DavidChristiansen/master
Kachow!
Diffstat (limited to 'src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs')
-rw-r--r--src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs b/src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs
new file mode 100644
index 0000000..bbeb861
--- /dev/null
+++ b/src/DotNetOpenAuth.ApplicationBlock/YammerConsumer.cs
@@ -0,0 +1,61 @@
+//-----------------------------------------------------------------------
+// <copyright file="YammerConsumer.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. 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 + "?oauth_verifier=" + 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, userCode);
+ return response;
+ }
+ }
+}