private static LightOpenID InitializeOpenID(IOwinContext request) { var openID = new LightOpenID(request.Request); openID.Realm = new Uri(request.Request.Uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)); openID.ReturnUrl = new Uri(openID.Realm, "/login/landing"); return(openID); }
public async Task HandleRequestAsync(IOwinContext request) { LightOpenID openID = InitializeOpenID(request); switch (request.Request.Uri.AbsolutePath) { case "/login": await AuthenticationRedirect(request, openID); break; case "/login/landing": await HandleLanding(request, openID); break; } }
private async Task HandleLanding(IOwinContext request, LightOpenID openID) { bool valid = await openID.Validate(); if (!valid) { request.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await request.Response.WriteAsync(FailureMessage); return; } if (openID.ClaimedID == null || !openID.ClaimedID.StartsWith(SteamClaimNamespace)) { request.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await request.Response.WriteAsync(FailureMessage); return; } long steamID64; if (!long.TryParse(openID.ClaimedID.Substring(SteamClaimNamespace.Length), out steamID64)) { request.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await request.Response.WriteAsync(FailureMessage); return; } var steamID = new SteamID(steamID64); if (!steamID.IsValid()) { request.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await request.Response.WriteAsync(FailureMessage); return; } await HandleValidLogin(request, steamID); }
private static async Task AuthenticationRedirect(IOwinContext request, LightOpenID openID) { string s = await openID.GetAuthUrl("http://steamcommunity.com/openid/"); request.Response.Redirect(s); }