lucuma
October 26, 2019, 10:25pm
1
I made a simple oath2provider that works fine, creates the userauth and details when directing back but I want the user to have an authenticated session when they are redirected to the success url: return authService.Redirect(redirectUrl);
The redirect URL in my case is an authenticated service.
For some reason when being redirected from the oauth flow and landing on that page (localhost/me) there is no authenticated session. I’m not sure if this is related to localhost or if there is something missing. Any ideas where to look?
mythz
October 26, 2019, 11:20pm
2
After validating the Access Token your OAuth Provider should call OnAuthenticated()
to setup the session, here’s FacebookAuthProvider
for reference:
var accessTokenUrl = $"{AccessTokenUrl}?client_id={AppId}&redirect_uri={this.CallbackUrl.UrlEncode()}&client_secret={AppSecret}&code={code}";
var contents = AccessTokenUrlFilter(this, accessTokenUrl).GetJsonFromUrl();
var authInfo = JsonObject.Parse(contents);
var accessToken = authInfo["access_token"];
return AuthenticateWithAccessToken(authService, session, tokens, accessToken)
?? authService.Redirect(SuccessRedirectUrlFilter(this, session.ReferrerUrl.SetParam("s", "1"))); //Haz Access!
//...
protected virtual object AuthenticateWithAccessToken(IServiceBase authService, IAuthSession session, IAuthTokens tokens, string accessToken)
{
tokens.AccessTokenSecret = accessToken;
var json = AuthHttpGateway.DownloadFacebookUserInfo(accessToken, Fields);
var authInfo = JsonObject.Parse(json);
session.IsAuthenticated = true;
return OnAuthenticated(authService, session, tokens, authInfo);
}
Failing that you should check that the same Session Cookies are being used before/after redirect.
lucuma
October 27, 2019, 12:38am
3
Thanks, it turned out to be the UseSecureCookies
needed to be set to false on localhost:
SetConfig(new HostConfig
{
DebugMode = AppSettings.Get("DebugMode", false),
WebHostPhysicalPath = MapProjectPath("~/wwwroot"),
UseCamelCase = true,
ReturnsInnerException = true,
AllowFileExtensions = { { "png" }, { "jpg" }, { "jpeg" } },
UseSecureCookies = false
});