I encounter an unauthorized error when using a token-based request for Google Docs in ASP.NET. The modified code sample below demonstrates my new approach. How should I correctly include a token secret?
public ActionResult InitiateAuth()
{
string redirectUrl = Request.Url.ToString().Replace("initiate", "display").ToLower();
string scopeUrl = "https://docs.google.com/feeds/";
string authLink = TokenHelper.GenerateAuthUrl(redirectUrl, scopeUrl, false, true);
return Redirect(authLink);
}
public ActionResult Display()
{
if (Request.QueryString["authParam"] != null)
{
string tempToken = Request.QueryString["authParam"];
string keyId = "site.example.com";
string secretKey = "secret123";
string sessionKey = TokenHelper.GetSessionToken(tempToken, null).ToString();
var reqFactory = new AuthRequestFactory("docApp", "app-002")
{
Token = sessionKey,
ConsumerKey = keyId,
ConsumerSecret = secretKey
};
try
{
var docService = new DocsService(reqFactory.AppName) { RequestFactory = reqFactory };
var queryRequest = new DocsQuery() { DocumentTitle = "project" };
var feed = docService.RunQuery(queryRequest);
return View(feed.Entries.Select(item => item.Title).ToList());
}
catch (ServiceException ex)
{
throw ex;
}
}
return null;
}