2014-06-11 3 views
1

MVC5 앱에서 간단한 Google+ 인증을 구현했으며 Google 캘린더에 액세스하고 싶습니다. MVC ID 시스템과 이미 인증 된 사용자를 사용하여이 작업을 수행하려면 어떻게해야합니까?Google 캘린더에 이미 인증 된 세션을 사용하려면 어떻게해야하나요?

Dim authGOps = New GooglePlusAuthenticationOptions() With { 
     .Caption = "Google+", 
     .ClientId = "MYCLIENTRID", 
     .ClientSecret = "MYCLIENTSECRET", 
     .Provider = New GooglePlusAuthenticationProvider() With { 
      .OnAuthenticated = Async Function(context) 
            context.Identity.AddClaim(New Claim(GooglePlusAccessTokenClaimType, context.AccessToken)) 
           End Function 
     } 
    } 


    authGOps.Scope.Add("https://www.googleapis.com/auth/calendar") 

    app.UseGooglePlusAuthentication(authGOps) 

달력 서비스 받기 : 그래서

Dim calendarService = New CalendarService(New Google.Apis.Services.BaseClientService.Initializer() With { 
WHAT GOES HERE TO AUTHENTICATE USING MY OLD AUTH CEDENTIALS? 
} 

답변

0

가 거의 모든 곳에서 문서화로 나뿐만 아니라 서비스를 사용하기 위해 사랑을,하지만 난 해결에 적어도 데이터를 가져 오는하고 있지 않는 발견 다시 로그인하십시오.

deserialize하고 강하게 입력하려면 Nuget Json.Net을 확인하십시오. 그렇지 않으면 관리 할 Json 문자열을 얻게됩니다.

C#이지만 번역이 너무 어렵지 않을 것이라고 확신합니다. 희망이 도움이됩니다!

var claimsIdentity = User.Identity as ClaimsIdentity; 
var claims = claimsIdentity.Claims; 

var accessTokenClaim = claims.FirstOrDefault(x => x.Type == GooglePlusAccessTokenClaimType); 

if (accessTokenClaim != null) 
{ 
    string calendarUrl = "https://www.googleapis.com/calendar/v3/users/me/calendarList?access_token=" + Uri.EscapeDataString(accessTokenClaim.Value); 

    using(var client = new HttpClient()) 
    { 
     var response = await client.GetAsync(calendarUrl); 
     var calendarList = JsonConvert.DeserializeObject<CalendarList>(await response.Content.ReadAsStringAsync()); 
    } 
}