Cas 4 attributes not return in ASP

631 views Asked by At

I have a project that redirect user to cas server and after user log in redirect it to my local (I'm using virtual host on IIS my.uk.ac.ir). Problem is that when it returns it doesnt return attribute. my project is on .net4.5.2 and using tls12

this is the original project that I modified. https://github.com/casinthecloud/dotnet-cas-client-demo

this is the link to modified project: https://github.com/HamidRezaAshkiyan/dotnet-cas-client-demo my modification is on dev branch.

Here is my web.config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient"/>
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <authentication mode="Forms">
      <forms name=".DotNetCasClientAuth" loginUrl="https://gate.uk.ac.ir" cookieless="UseCookies"/>
    </authentication>
    <httpModules>
      <add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
    </httpModules>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="DotNetCasClient"/>
      <add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
    </modules>
  </system.webServer>
  <casClientConfig casServerLoginUrl="https://gate.uk.ac.ir" casServerUrlPrefix="https://gate.uk.ac.ir" serverName="https://my.uk.ac.ir/" notAuthorizedUrl="~/NotAuthorized.aspx" cookiesRequiredUrl="~/CookiesRequired.aspx" redirectAfterValidation="true" gateway="false" renew="false" singleSignOut="true" ticketTimeTolerance="5000" ticketValidatorName="Cas10" proxyTicketManager="CacheProxyTicketManager" serviceTicketManager="CacheServiceTicketManager" gatewayStatusCookieName="CasGatewayStatus"/>
</configuration>

this is my index page where redirects after login:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="dotnet_cas_client_demo.secure.index" %>

<asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">

    <ul class="nav nav-tabs">
        <li><a href="/index.aspx">Call the /index.aspx page</a></li>
        <li class="active"><a href="/secure/index.aspx">You are on the /secure/index.aspx page</a></li>
        <!-- #### change with your own CAS server and your host name #### -->
        <li><a href="http://gate.uk.ac.ir/logout?service=https://my.uk.ac.ir/">Call the CAS logout</a></li>
    </ul>
    <h3>
        <p>username: <span id="username" runat="server" /></p>
        
        <p>AttributeCount: <span id="attributes" runat="server" /></p>
        <p>Attribute: <span id="attribute" runat="server" /></p>
        

    </h3>

</asp:Content>

this is the backend code:

using System;

namespace dotnet_cas_client_demo.secure
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // get the current authenticated user
            username.InnerText = System.Web.HttpContext.Current.User.Identity.Name;

            attributes.InnerText = CasAuthentication.CurrentPrincipal.Assertion.Attributes.Count.ToString();
        }
    }
}

I'm not sure that the right way of getting the attributes or not.

I've tried this solution for java but not helped me. Cas no attributes come to client

there where similar problem on php and my coworkers solved it with cas protocol 3 and i saw similar on the answer above.

1

There are 1 answers

0
Hamid Reza Ashkiyan On BEST ANSWER

After a lot of googling I found that this library doesnt support cas protocol 3 and I found another library that works on .net core 3 and support 3 by default: https://github.com/akunzai/GSS.Authentication.CAS

it helped me getting attributes.

Apereo library are working on supporting protocol 3.