Skip to content

Instantly share code, notes, and snippets.

@gsiener
Created February 3, 2012 01:25
Show Gist options
  • Save gsiener/1727012 to your computer and use it in GitHub Desktop.
Save gsiener/1727012 to your computer and use it in GitHub Desktop.
Blue Dot Menu
/*
* Copyright (c) 2011 Intuit, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.opensource.org/licenses/eclipse-1.0.php
* Contributors:
*
* Intuit Partner Platform - initial contribution
*
*/
using System;
using System.Configuration;
using System.IO;
using System.Net;
using System.Web;
using DevDefined.OAuth.Consumer;
using DevDefined.OAuth.Framework;
using IntuitAnywhere.utils;
namespace IntuitAnywhere
{
public partial class MenuProxy : System.Web.UI.Page
{
private String txtServiceResponse = "";
protected void Page_Load(object sender, EventArgs e)
{
//_oauthToken = HttpContext.Current.Session["oauthToken"].ToString();
if (HttpContext.Current.Session.Keys.Count > 0)
{
GetBlueDotMenu();
}
}
protected void GetBlueDotMenu()
{
HttpContext.Current.Session["serviceEndPoint"] = Constants.IaEndPoints.BlueDotAppMenuUrl;
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{
ConsumerKey = HttpContext.Current.Session["consumerKey"].ToString(),
SignatureMethod = SignatureMethod.HmacSha1,
ConsumerSecret = HttpContext.Current.Session["consumerSecret"].ToString()
};
OAuthSession oSession = new OAuthSession(consumerContext, Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlRequestToken,
Constants.OauthEndPoints.AuthorizeUrl,
Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlAccessToken);
oSession.ConsumerContext.UseHeaderForOAuthParameters = true;
oSession.AccessToken = new TokenBase
{
Token = HttpContext.Current.Session["accessToken"].ToString(),
ConsumerKey = HttpContext.Current.Session["consumerKey"].ToString(),
TokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString()
};
IConsumerRequest conReq = oSession.Request();
conReq = conReq.Get();
conReq = conReq.ForUrl(HttpContext.Current.Session["serviceEndPoint"].ToString());
conReq = conReq.SignWithToken();
string header = conReq.Context.GenerateOAuthParametersForHeader();
try
{
txtServiceResponse = conReq.ReadBody();
Response.Write(txtServiceResponse);
}
catch (WebException we)
{
HttpWebResponse rsp = (HttpWebResponse)we.Response;
if (rsp != null)
{
try
{
using (StreamReader reader = new StreamReader(rsp.GetResponseStream()))
{
txtServiceResponse = txtServiceResponse + rsp.StatusCode + " | " + reader.ReadToEnd();
}
}
catch (Exception)
{
txtServiceResponse = txtServiceResponse + "Status code: " + rsp.StatusCode;
}
}
else
{
txtServiceResponse = txtServiceResponse + "Error Communicating with Intuit Anywhere" + we.Message;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment