OpenId and Google Calander Api

103 views
Skip to first unread message

mobi

unread,
Jan 3, 2012, 1:13:10 AM1/3/12
to DotNetOpenAuth
I am lost in connecting dots between DotnetOpenAuth and Google
Calander API.

I am able to get DotnetOpenAuth on my website working which
authenticates the user with gmail id and even fetch the email id.

Now my question is how do I go from here to get the authorization of
this user to access his calander using the google calendar api.

I used dotnetopenauth api code snippet below

openid.cs

========================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;

namespace MobileJobing.App.Auth
{
public class OpenId
{
private OpenIdRelyingParty _openIdRelyingParty { get; set; }
private IAuthenticationResponse _response { get; set; }

public OpenId()
: this(null)
{

}

public OpenId(OpenIdRelyingParty relyingParty)
{
_openIdRelyingParty = relyingParty ?? new
OpenIdRelyingParty();
}

public OpenIdentity ProcessOpenId(string openId)
{
_response = _openIdRelyingParty.GetResponse();



if (_response == null)
{
Authenticate(openId);
return null;
}

return Verify();


}

public void Authenticate(string openId)
{
Identifier id;
if (Identifier.TryParse(openId, out id))
{


//
_openIdRelyingParty.CreateRequest(id).RedirectingResponse.Send();


using (_openIdRelyingParty)
{
IAuthenticationRequest request =
_openIdRelyingParty.CreateRequest(openId);

var fetch = new FetchRequest();

fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(fetch);

//Is there a way here to call the google
calander api

// Send your visitor to their Provider for
authentication.
request.RedirectToProvider();
}






}
else
{
throw new ApplicationException("Invalid Identifier");
}
}

public OpenIdentity Verify()
{
var oid = new OpenIdentity();

switch (_response.Status)
{
case AuthenticationStatus.Authenticated:
oid.Id = _response.ClaimedIdentifier;

var fetch =
_response.GetExtension<FetchResponse>();
string email = string.Empty;
if (fetch != null)
{
oid.Username =
fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
// oid.Username =
_response.FriendlyIdentifierForDisplay;
break;
case AuthenticationStatus.Canceled:
throw new ApplicationException("Canceled at
Provider");
case AuthenticationStatus.Failed:
throw new
ApplicationException(_response.Exception.Message);
}

return oid;
}
}
}

==============================

The above code is for getting the authentication peace working. Now I
am trying to add the below

using Google.GData.Calendar;
using Google.GData.Extensions;
using Google.GData.Client;

and then get on to the next level of authorization from the user. But
am lost from here. Can some one help me on how to call the google
calander api using the credentials already provided by the user when
authenticating.

Andrew Arnott

unread,
Jan 3, 2012, 1:26:52 AM1/3/12
to dotnet...@googlegroups.com
Do you need to authenticate the user using Google, or do you merely need access to his Calendar?

If you just need his Calendar, use OAuth, and there's a sample for accessing Google Contacts that ships with DotNetOpenAuth using OAuth.  

If you need the user to authenticate with Google and have access to his calendar, then you want to use OpenID with the "OpenID+OAuth" extension, which gives you the OAuth access token that you need to then pass to the GData API to download their calendar.  I'm pretty sure there's an OpenID+OAuth extension sample with DotNetOpenAuth too.

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre



--
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.


mobi

unread,
Jan 3, 2012, 10:22:38 AM1/3/12
to DotNetOpenAuth
Thanks for the immediate reply. You got me right am trying to get
both :

If you need the user to authenticate with Google *and* have access to
his
calendar, then you want to use OpenID with the "OpenID+OAuth"
extension,
which gives you the OAuth access token that you need to then pass to
the
GData API to download their calendar. I'm pretty sure there's an
OpenID+OAuth extension sample with DotNetOpenAuth too.

This gives me few pointers to go search more. It is so much confusing
with these authentication and authorization stuff. I really appreciate
if you can forward me specific links or pointers especially from
Asp.net MVC and razor view. Is there a nuget package out there for
both OpenID+OAuth extension. Been searching a lot and get all these
confusing links here and there.



On Jan 3, 1:26 am, Andrew Arnott <andrewarn...@gmail.com> wrote:
> Do you need to authenticate the user using Google, or do you merely need
> access to his Calendar?
>
> If you just need his Calendar, use OAuth, and there's a sample for
> accessing Google Contacts that ships with DotNetOpenAuth using OAuth.
>
> If you need the user to authenticate with Google *and* have access to his

Andrew Arnott

unread,
Jan 4, 2012, 10:10:11 AM1/4/12
to dotnet...@googlegroups.com
Hi mobi,

If you check out the OpenIdRelyingPartyWebForms sample's loginPlusOAuth.aspx file and its code-behind, you'll see an OpenID+OAuth example where the user logs in with Google and then the sample shows their Google Contacts list that the sample downloaded using OAuth.  

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre


Reply all
Reply to author
Forward
0 new messages