secret
Last active

Functional Vimeo OpenAuth test.

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VimeoCommon;
using VimeoObject;
using VimeoObject.Enums;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.Messaging;
using OpenIdRelyingPartyWebForms.Code;
 
namespace Vimeo
{
public partial class Authenticate : System.Web.UI.Page
{
public string AccessToken
{
get { return (string)HttpContext.Current.Session["VimeoAccessToken"]; }
set { HttpContext.Current.Session["VimeoAccessToken"] = value; }
}
 
/// <summary>
/// OAuth token manager
/// </summary>
private InMemoryTokenManager TokenManager
{
get
{
var tokenManager = (InMemoryTokenManager)Application["VimeoTokenManager"];
if (tokenManager == null)
{
string consumerKey = "key here";
string consumerSecret = "secret here";
 
if (!string.IsNullOrEmpty(consumerKey))
{
tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
Application["VimeoTokenManager"] = tokenManager;
}
}
 
return tokenManager;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.TokenManager != null)
{
if (!IsPostBack)
{
ServiceProviderDescription vimeoSPD = new ServiceProviderDescription
{
AccessTokenEndpoint = new MessageReceivingEndpoint("https://vimeo.com/oauth/access_token", HttpDeliveryMethods.GetRequest),
RequestTokenEndpoint = new MessageReceivingEndpoint("https://vimeo.com/oauth/request_token", HttpDeliveryMethods.GetRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://vimeo.com/oauth/authorize", HttpDeliveryMethods.GetRequest),
TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
ProtocolVersion = ProtocolVersion.V10a
};
var vimeoConsumer = new WebConsumer(vimeoSPD, this.TokenManager);
 
var accessTokenResponse = vimeoConsumer.ProcessUserAuthorization();
if (accessTokenResponse != null)
{
this.AccessToken = accessTokenResponse.AccessToken;
Results.Text = this.AccessToken;
}
else if (this.AccessToken == null)
{
string thisUrl = HttpContext.Current.Request.Url.AbsoluteUri;
vimeoConsumer.Channel.Send(vimeoConsumer.PrepareRequestUserAuthorization(new Uri(thisUrl), new Dictionary<string, string>(), new Dictionary<string, string>()));
}
}
}
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.