private void ProcessToken() { OpenIdRpxHelper rpxHelper = new OpenIdRpxHelper(rpxApiKey, rpxBaseUrl); OpenIdRpxAuthInfo authInfo = rpxHelper.AuthInfo(authToken, tokenUrl); if ((authInfo == null) || (!authInfo.IsValid)) { Response.Redirect(SiteRoot + "/Secure/Login.aspx"); return; } if (Request.IsAuthenticated) { HandleAuthenticatedUser(rpxHelper, authInfo); return; } Guid userGuid = Guid.Empty; SiteUser user = null; //first find a site user by email // this allows associating the openid user with an existing user. if ((authInfo.Email.Length > 0)) { user = SiteUser.GetByEmail(siteSettings, authInfo.Email); } if (authInfo.PrimaryKey.Length == 36) { try { userGuid = new Guid(authInfo.PrimaryKey); } catch (FormatException) { } catch (OverflowException) { } } if ((user == null)&&(userGuid == Guid.Empty)) { userGuid = SiteUser.GetUserGuidFromOpenId( siteSettings.SiteId, authInfo.Identifier); } if ((user == null) && (userGuid != Guid.Empty)) { user = new SiteUser(siteSettings, userGuid); if (WebConfigSettings.UseRelatedSiteMode) { if (user.UserId == -1) { user = null; } // user not found } else { if (user.SiteGuid != siteSettings.SiteGuid) { user = null; } //user not connected to this site } } if (user == null) { // not an existing user if (siteSettings.AllowNewRegistration) { HandleNewUser(rpxHelper, authInfo); } else { WebUtils.SetupRedirect(this, SiteRoot); return; } } else { bool needToSave = false; if ((siteSettings.UseSecureRegistration)&& (user.RegisterConfirmGuid != Guid.Empty)) { if (authInfo.VerifiedEmail.Length > 0) { user.SetRegistrationConfirmationGuid(Guid.Empty); user.Email = authInfo.VerifiedEmail; needToSave = true; } } if (user.OpenIdUri.Length == 0) { user.OpenIdUri = authInfo.Identifier; needToSave = true; } if (needToSave) { user.Save(); } if (WebConfigSettings.OpenIdRpxUseMappings) { if ((authInfo.PrimaryKey.Length == 0) || (authInfo.PrimaryKey != user.UserGuid.ToString())) { rpxHelper.Map(authInfo.Identifier, user.UserGuid.ToString()); } } SignInUser(user, false); } }
private void ProcessToken() { OpenIdRpxHelper rpxHelper = new OpenIdRpxHelper(rpxApiKey, rpxBaseUrl); OpenIdRpxAuthInfo authInfo = rpxHelper.AuthInfo(authToken, tokenUrl); if ((authInfo == null) || (!authInfo.IsValid)) { log.Debug($"openid-debug: authInfo is null or authInfo.IsValid='false' "); Response.Redirect(SiteRoot + "/Secure/Login.aspx"); return; } if (Request.IsAuthenticated) { log.Debug($"openid-debug: authInfo is valid and user exists, authenticated "); HandleAuthenticatedUser(rpxHelper, authInfo); return; } Guid userGuid = Guid.Empty; SiteUser user = null; //first find a site user by email // this allows associating the openid user with an existing user. if ((authInfo.Email.Length > 0)) { log.Debug($"openid-debug: found user by email "); user = SiteUser.GetByEmail(siteSettings, authInfo.Email); } if (authInfo.PrimaryKey.Length == 36) { try { userGuid = new Guid(authInfo.PrimaryKey); } catch (FormatException) { } catch (OverflowException) { } } if ((user == null) && (userGuid == Guid.Empty)) { userGuid = SiteUser.GetUserGuidFromOpenId( siteSettings.SiteId, authInfo.Identifier); } if ((user == null) && (userGuid != Guid.Empty)) { user = new SiteUser(siteSettings, userGuid); if (WebConfigSettings.UseRelatedSiteMode) { if (user.UserId == -1) { user = null; log.Debug($"openid-debug: user not found "); } } else if (user.SiteGuid != siteSettings.SiteGuid) { user = null; log.Debug($"openid-debug: user not connected to this site ({siteSettings.SiteId.ToString()}) "); } } if (user == null) { // not an existing user if (siteSettings.AllowNewRegistration) { HandleNewUser(rpxHelper, authInfo); } else { log.Debug($"openid-debug: user not found, AllowNewRegistrations='false' "); WebUtils.SetupRedirect(this, SiteRoot); return; } } else { log.Debug($"openid-debug: user found ({user.LoweredEmail}, {user.UserId.ToString()}) "); bool needToSave = false; if ((siteSettings.UseSecureRegistration) && (user.RegisterConfirmGuid != Guid.Empty)) { if (authInfo.VerifiedEmail.Length > 0) { user.SetRegistrationConfirmationGuid(Guid.Empty); user.Email = authInfo.VerifiedEmail; needToSave = true; } } if (user.OpenIdUri.Length == 0) { user.OpenIdUri = authInfo.Identifier; needToSave = true; } if (needToSave) { user.Save(); } if (WebConfigSettings.OpenIdRpxUseMappings) { if ((authInfo.PrimaryKey.Length == 0) || (authInfo.PrimaryKey != user.UserGuid.ToString())) { rpxHelper.Map(authInfo.Identifier, user.UserGuid.ToString()); } } SignInUser(user, false); } }
private void ProcessToken() { OpenIdRpxHelper rpxHelper = new OpenIdRpxHelper(rpxApiKey, rpxBaseUrl); OpenIdRpxAuthInfo authInfo = rpxHelper.AuthInfo(authToken, tokenUrl); if ((authInfo == null) || (!authInfo.IsValid)) { Response.Redirect(SiteRoot + "/Secure/Login.aspx"); return; } if (Request.IsAuthenticated) { HandleAuthenticatedUser(rpxHelper, authInfo); return; } Guid userGuid = Guid.Empty; SiteUser user = null; //first find a site user by email if ((authInfo.Email.Length > 0)) { user = SiteUser.GetByEmail(siteSettings, authInfo.Email); } if (authInfo.PrimaryKey.Length == 36) { try { userGuid = new Guid(authInfo.PrimaryKey); } catch (FormatException) { } catch (OverflowException) { } } if ((user == null) && (userGuid == Guid.Empty)) { userGuid = SiteUser.GetUserGuidFromOpenId( siteSettings.SiteId, authInfo.Identifier); } if ((user == null) && (userGuid != Guid.Empty)) { user = new SiteUser(siteSettings, userGuid); if (user.SiteGuid != siteSettings.SiteGuid) { user = null; } } if (user == null) { // not an existing user if (siteSettings.AllowNewRegistration) { HandleNewUser(rpxHelper, authInfo); } else { WebUtils.SetupRedirect(this, SiteRoot); return; } } else { bool needToSave = false; if ((siteSettings.UseSecureRegistration) && (user.RegisterConfirmGuid != Guid.Empty)) { if (authInfo.VerifiedEmail.Length > 0) { user.SetRegistrationConfirmationGuid(Guid.Empty); user.Email = authInfo.VerifiedEmail; needToSave = true; } } if (user.OpenIdUri.Length == 0) { user.OpenIdUri = authInfo.Identifier; needToSave = true; } if (needToSave) { user.Save(); } if (WebConfigSettings.OpenIdRpxUseMappings) { if ((authInfo.PrimaryKey.Length == 0) || (authInfo.PrimaryKey != user.UserGuid.ToString())) { rpxHelper.Map(authInfo.Identifier, user.UserGuid.ToString()); } } SignInUser(user); } }