I have made an application for sending the calendar events to the client in my application. My Code is:
namespace NotInstalled.Service
{
public class AppFlowMetadata : FlowMetadata
{
private static readonly IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "CLIENT_ID",
ClientSecret = "CLIENT_SECRET"
},
Scopes = new[] { "https://www.googleapis.com/auth/calendar.events" },
DataStore = new FileDataStore("Calendar.Api.Auth.Store")
});
public override string GetUserId(Controller controller)
{
var user = controller.Session["user"];
if (user == null)
{
user = Guid.NewGuid();
controller.Session["user"] = user;
}
return user.ToString();
}
public override IAuthorizationCodeFlow Flow
{
get { return flow; }
}
}
}
And my code for sending the events is :
public async Task<ActionResult> Contact(CancellationToken cancellationToken)
{
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
AuthorizeAsync(cancellationToken);
if (googleSerive.RedirectUri != null)
{
return Redirect(googleSerive.RedirectUri);
}
if (result.Credential != null)
{
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = result.Credential,
ApplicationName = ApplicationName,
});
//Events Snending Code Here which works perfectly
return View();
}
return View();
}
and my auth call back controller is :
public class AuthCallbackController : Google.Apis.Auth.OAuth2.Mvc.Controllers.AuthCallbackController
{
protected override Google.Apis.Auth.OAuth2.Mvc.FlowMetadata FlowData
{
get { return new AppFlowMetadata(); }
}
}
Now Each Time I open the application and go through Contact
Method in a different browser It asks me to login with my gamil used in this Google API.I have already authorize my account and also i have token for it.How can I use the same token for usercredentials and use the service.