How to do redirect after authentication in STS?

2

My application authenticates users through STS. Authentication can go to the STS and validate the user PIN on the card. But how do I redirect it to the "home" page of my site after authentication?

Addendum:

  • I do not have access to the STS admin;
  • I use the FederatedPassiveSignIn pendent component contained in: Microsoft.IdentityModel.Web.Controls ;
  • I tried to use the Signed_in method to try to capture the moment after the authentication to STS but it did not work;
  • The way I was able to do redirect previously was by using Event Load , however, it runs every time the page is loaded (obvious).
  • Follow Code:

    <div style="margin-left: 360px; margin-top: 100px; margin-bottom: 100px;">
            <wif:FederatedPassiveSignIn ID="FederatedPassiveSignIn1" runat="server"
                Issuer="<%$AppSettings:CORP.STS.Certificado%>"
                RequireHttps="False" Realm="<%$AppSettings:CORP.STS.UrlCliente%>"
                UseFederationPropertiesFromConfiguration="false" RememberMeText="Lembre minha Senha."
                SignInImageUrl="~/Images/ec_b.gif" TitleText="Autenticar Certificado Digital" OnSignedIn="FederatedPassiveSignIn1_SignedIn" >
                <SignInButtonStyle Height="80px" />
            </wif:FederatedPassiveSignIn>
            <div id="errorMessage">
                <asp:Label Text="text" ID="lblError" runat="server" Visible="false" ForeColor="Red" style="margin-left:-200px;" />
            </div>
        </div>
    

    and the code behind part:

     protected void FederatedPassiveSignIn1_SignedIn(object sender, EventArgs e)
     {
         Response.Redirect("MinhaPagina.aspx");
     }
    
        
    asked by anonymous 26.02.2014 / 15:12

    1 answer

    0

    I managed to get around this way ... not the best way, (I believe) but it works.

    protected void FederatedPassiveSignIn1_Load(object sender, EventArgs e)
            {
                if (IsPostBack) return;
    
                try
                {
    
                    var principal = Thread.CurrentPrincipal as IClaimsPrincipal;
                    if (principal == null || !principal.Identity.IsAuthenticated) return;
    
                    var identity = (IClaimsIdentity)principal.Identity;
                    string userId = "";
                    var cpf = "";
                    foreach (var c in identity.Claims.Where(c => c.ClaimType.ToLower().Contains("login")))
                        userId = c.Value;
    
                    var usuario = ObterUsuario(principal);
                    var juris = new ServicoJurisdicao.JurisdicaoClient();
                    var jurisdicoesDeUsuario = juris.ConsultarJurisdicoesUsuario(usuario);
    
                    foreach (var jurisdicao in jurisdicoesDeUsuario)
                    {
                        identity.Claims.Add(new Claim("http://schemas.CORP.com.br/identity/claims/Jurisdicao", jurisdicao.ToString(),
                            ClaimValueTypes.String, ObterNomeEmissor()));
                    }
    
                    //Cada claim possui também um tipo, uma string que define o tipo de informação contida:
                    Response.Write("Tipo de Claim: " + identity.Claims[0].ClaimType);
    
    
                    var lookupIpAddres = Request.ServerVariables["REMOTE_HOST"];
                    var ipAddress = Request.UserHostAddress;
    
                    var sessionProxy = SessionProxy.getInstance();
                    sessionProxy.setConfUserIP(ipAddress);
                    sessionProxy.setConfUserId(userId);
                    sessionProxy.setIdentity(identity);
    
                    /*Forms authentication*/
                    FormsAuthentication.SetAuthCookie(userId, true);
                    /*Forms authentication*/
                    Response.Redirect(ResolveUrl("~/"));
                }
    
                catch (Exception err)
                {
                    lblError.Text = err.Message;
                    PECv2.Handlers.SimpleLog.SaveLogEventvwrError(err, "PecV2 - Login");
                    lblError.Visible = true;
                    return;
                }
            }
    
        
    06.03.2014 / 15:21