1
我用dotnetOpenAuth。我想向用戶的gamil請求授權。想用dotnetOpenAuth請求gmail授權
我需要先使用openId嗎?
找不到像樣的tutorail。誰能幫忙?
嘗試此代碼unsuccesfully。反正我不似乎要求在身份驗證請求Gmail的範圍,所以我很困惑
public void PrepareAuthorizationRequest(Uri authCallbakUrl)
{
var consumer = new WebConsumer(GoogleConsumerConsts.ServiceDescription, mConsumerTokenManager);
// request access
consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authCallbakUrl, null, null));
throw new NoRedirectToAuthPageException();
}
public ProcessAuthorizationRequestResponse ProcessAuthorizationRequest()
{
ProcessAuthorizationRequestResponse response;
// Process result from the service provider
var consumer = new WebConsumer(GoogleConsumerConsts.ServiceDescription, mConsumerTokenManager);
var accessTokenResponse = consumer.ProcessUserAuthorization();
// If we didn't have an access token response, this wasn't called by the service provider
if (accessTokenResponse == null)
response = new ProcessAuthorizationRequestResponse
{
IsAuthorized = false
};
else
{
// Extract the access token
string accessToken = accessTokenResponse.AccessToken;
response = new ProcessAuthorizationRequestResponse
{
IsAuthorized = true,
Token = accessToken,
Secret = mConsumerTokenManager.GetTokenSecret(accessToken)
};
}
return response;
}
private string Test2()
{
// Process result from linked in
var google = new WebConsumer(GoogleConsumerConsts.ServiceDescription, mConsumerTokenManager);
// var accessToken = GetAccessTokenForUser();
var accessToken = String.Empty;
// Retrieve the user's profile information
var endpoint = GoogleConsumerConsts.GetGmailFeedsEndpoint;// new MessageReceivingEndpoint("http://api.linkedin.com/v1/people/~", HttpDeliveryMethods.GetRequest);
var request = google.PrepareAuthorizedRequest(endpoint, accessToken);
var response = request.GetResponse();
return (new StreamReader(response.GetResponseStream())).ReadToEnd();
}
如果我不使用openAuth,我應該在數據庫中保存什麼,以便下次識別用戶? requestToken是永久且唯一的嗎?第二次使用者的流量是多少? – 2012-03-04 22:26:06
請求令牌或訪問令牌不是持久的。如果您希望能夠在下次識別用戶時,可以使用OpenID *(除了OAuth之外還可以實際閱讀他們的Gmail)。在這種情況下,您應該查看'openidrelyingpartywebforms/loginplusoauth.aspx'示例,這些示例使用Google *登錄用戶,以及*訪問其Gmail地址簿。 – 2012-03-05 01:06:57
它會導致用戶雙重重定向?一次用於身份驗證,一次用於授權? – 2012-03-05 19:00:15