I am developing a singe sign on solution and need to be able to log a user into their Google account whenever they use visit the site so they can access any Google services. I am getting access and refresh token from google and saving them to my database but I don't know what to do with these tokens to log the user in.
public async Task<ActionResult> IndexAsync(CancellationToken cancellationToken)
{
flowData = new AppFlowMetadata();
UsersSSOTokens userToken = GetCurrentUserToken();
if (userToken != null)
{
CheckTokenValid(userToken);
LogIntoGoogleWithToken();
}
else
if (result == null || result.Credential == null)
{
result = await new AuthorizationCodeMvcApp(this, flowData).
AuthorizeAsync(cancellationToken);
if (result.Credential == null) return new RedirectResult(result.RedirectUri);
}
return View();
}
public async Task<ActionResult> GetResult(string code, string error, string state)
{
var returnUrl = Request.Url.ToString();
returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?"));
var userId = Session["user"];
var token = await flowData.Flow.ExchangeCodeForTokenAsync(userId.ToString(), code, returnUrl,
CancellationToken.None);
if (token != null && error == null)
{
if (token.AccessToken != null && token.RefreshToken != null)
SaveToken(token.AccessToken, token.RefreshToken, token.TokenType, token.Issued, token.Scope);
}
return new RedirectResult(state);
}