지난 2 일 동안 MVC Implementation of OAuthConsumer Sample for DotNetOpenAuth에서 그물을 검색했지만 여전히 해결책을 찾지 못했습니다. OAuthConsumer 구현을 WebForms에서 MVC로 변환하려고했지만 여전히 올바르게 구현할 수 없었습니다. 누구든지 변환기 샘플을 찾을 수있는 장소를 참조하여 도움을받을 수 있습니다.MVC DotNetOpenAuth의 OAuthConsumer 구현 특히 Google 주소록
2
A
답변
1
투쟁 2 일 후 나는 다음과 같이이 문제를 해결했지만 좀 더 개선이 필요하다고 생각합니다.
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["GoogleOAuthConsumerKey"];
string consumerSecret = ConfigurationManager.AppSettings["GoogleOAuthConsumerValue"];
if (!string.IsNullOrEmpty(consumerKey))
{
tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
HttpContext.Application["GoogleTokenManager"] = tokenManager;
}
}
return tokenManager;
}
}
public ActionResult GoogleSync()
{
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;
XDocument contactsDocument = GoogleConsumer.GetContacts(google, this.AccessToken, 5, 1);
var contactList = new List<GMailContact>();
foreach (var entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom")))
{
GMailContact newContact = new GMailContact { Name = string.Empty, Email = string.Empty };
var titleElement = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom"));
if (titleElement != null)
newContact.Name = titleElement.Value;
var emailElement = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005"));
if (emailElement != null && emailElement.Attribute("address") != null)
{
newContact.Email = emailElement.Attribute("address").Value;
}
contactList.Add(newContact);
}
////var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
//// select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value,
//// Email = (XName.Get("email", "http://schemas.google.com/g/2005") == null ? "" : entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value) };
return View(contactList);
}
else if (this.AccessToken == null)
{
// If we don't yet have access, immediately request it.
GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Contacts);
return this.Content("");
}
else
{
return this.Content("synchronization failed.");
}
}
0
내가 알고있는 OAuth 소비자의 MVC 샘플이 없습니다. 그러나 OAuth 소비자는 프레젠테이션 프레임 워크와 아무런 관련이 없으므로 웹 양식과 MVC간에 차이가 없어야합니다. 소비자 관련 코드를 웹 양식 샘플에서 직접 추출하여 MVC에서 사용할 수 있어야합니다.
그래도 문제가 해결되지 않으면보고있는 문제에 대해 설명하는 질문을 추가하십시오.
관련 문제
- 1. "내 주소록"그룹 Google 주소록
- 2. .NET의 휴대용 주소록 구현
- 3. 전화 주소록 구현 - 역 색인
- 4. 는 OAuthConsumer - OAMutableURLRequest
- 5. Google 주소록 검색 Zend 사용
- 6. Quora는 어떻게 주소록 가져 오기를 구현 했습니까?
- 7. SystemPropertiesAdvanced.exe (특히 SYSDM) 구현 세부 사항
- 8. Google 주소록 읽기 전용 (OAuth 2.0)
- 9. Google 주소록 API에 대한 쿼리 제한
- 10. Google 이미지 검색 구현
- 11. .Net 3.5로 MVC 구현
- 12. asp.net mvc returnurl 구현
- 13. MVC 모델 구현?
- 14. MVC (Asp.Net MVC 특히)에서 모델을 단일 뷰로 나타내야합니까? 나에게
- 15. Google App Engine에서 태그 구현
- 16. Google Mercator (Spherical Mercator) 구현
- 17. Google 스타일 "구현하셨습니까?"구현 방법
- 18. Google OpenID-OAuth 하이브리드 구현
- 19. 주소록 청취자
- 20. Popover의 주소록
- 21. Google Analytics 및 MVC?
- 22. Google Apps 공유 주소록 API Python 연락처 받기
- 23. MVC 면도기 뷰에서 Jquery.ShowPassword 구현
- 24. 세련된 검색 구현 - ASP.NET MVC
- 25. MVC : 사용자 메시지 스택 구현
- 26. MVC - 회원 구현 온라인 기능
- 27. JPA를 사용할 때 MVC 구현
- 28. ASP.NET MVC 사용자 메시징 구현
- 29. ASP.NET MVC 바쁜 박스 구현
- 30. MVC 아키텍처에서 서비스 레이어 구현
답장을 보내 주신 2 주 동안의 고민 끝에 다음과 같이 문제가 해결되었지만 개선이 필요하다고 생각됩니다. 개선이 필요한 장소를 확인하고 식별 할 수 있습니까? – Abdul