Hi Andrew,
I'm in the process of merging a project created with the
ASP.NET MVC
OpenID-Infocard RP template, and the OAuth consumer sample.
I have a ContactsController, with an Index action as follows,
//The block of code withing the if authenticated was borrowed
from the GoogleAddressBook.asp.cs Page_Load method.
public ActionResult Index()
{
//if (Page.User.Identity.IsAuthenticated)
if (Request.IsAuthenticated)
{
var google = new
WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager);
// Is Google calling back with authorization?
var accessTokenResponse =
google.ProcessUserAuthorization();
if (accessTokenResponse != null)
{
this.AccessToken =
accessTokenResponse.AccessToken;
}
else if (this.AccessToken == null)
{
// If we don't yet have access, immediately
request it.
GoogleConsumer.RequestAuthorization(google,
GoogleConsumer.Applications.Contacts);
}
ViewData["AuthTokens"] =
Database.LoggedInUser.AuthenticationTokens;
return View();
}
else
{
return Redirect("/Home");
}
}
//with class properties:
private string AccessToken
{
get { return (string)Session["GoogleAccessToken"]; }
set { Session["GoogleAccessToken"] = value; }
}
private InMemoryTokenManager TokenManager
{
get
{
var tokenManager =
(InMemoryTokenManager)HttpContext.Application["GoogleTokenManager"];
if (tokenManager == null)
{
string consumerKey =
ConfigurationManager.AppSettings["googleConsumerKey"];
string consumerSecret =
ConfigurationManager.AppSettings["googleConsumerSecret"];
if (!string.IsNullOrEmpty(consumerKey))
{
tokenManager = new
InMemoryTokenManager(consumerKey,
consumerSecret);
HttpContext.Application["GoogleTokenManager"]
= tokenManager;
}
}
return tokenManager;
}
}
This code fails on RelyingPartyLogic/
OAuthServiceProviderTokenManager.GetRequestToken(string token),
because it fails to find the issued token in the database. The issued
token is stored in memory.
Some questions:
1. How is RelyingPartyLogic/
OAuthServiceProviderTokenManager.GetRequestToken triggered in the
GoogleConsumer.RequestAuthorization step?
2. I'm not sure InMemoryTokenManager is what I need since I'd expect
to user to request access only once. I tried changing
InMemoryTokenManager for OAuthConsumerTokenManager with no luck, I get
ArgumentOutOfRangeException on StoreNewRequestToken. At the moment I'm
storing consumer key and secret in the web.config, shouldnt this be
stored in the database? Am I missing some db initialization for my
consumer?
thanks,
gabo
--
You received this message because you are subscribed to the Google Groups "DotNetOpenAuth" group.
To post to this group, send email to
dotnet...@googlegroups.com.
To unsubscribe from this group, send email to
dotnetopenid...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/dotnetopenid?hl=en.