locked
Enable Single Sign on Using Asp.Net Identity RRS feed

  • Question

  • User611346789 posted

    How can i enable Single Sign On using Asp.Net Identity Without Forms Authentication??? Is it possible ??

    Can anyone please help me to implement ??

    Wednesday, November 14, 2018 9:42 AM

Answers

All replies

  • User753101303 posted

    Hi,

    emrulkayes2103

    Without

    Tell rather what you want to use ? Sounds you want to use https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-2.1 

    Edit: or you want to have your own identity server such as https://identityserver4.readthedocs.io/en/release/  ? The first step is likely to understand where accounts are authenticated. They are stored in a db or in AD ?

    Wednesday, November 14, 2018 9:53 AM
  • User611346789 posted

    Thank your for your reply. User information will be stored in Db and want to use Asp.Net OWIN Identity. I have added below line of code  after login successfully

    protected void CreateCookieForAuthentication(ApplicationUser userDetails, bool isPersistent = false)
    {
    var claims = new List<Claim>();

    claims.Add(new Claim(ClaimTypes.NameIdentifier, userDetails.Id));
    claims.Add(new Claim(ClaimTypes.Name, userDetails.UserName));

    var identity = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie);

    AuthenticationManager.SignIn(new AuthenticationProperties()
    {
    AllowRefresh = true,
    IsPersistent = isPersistent,
    ExpiresUtc = Core.GetServerDatetime().AddMinutes(35000),
    IssuedUtc = Core.GetServerDatetime()
    },identity);
    }

    But when i am running Second application then got error that IIS Access Denied. unauthorized access?? I have only configure startup.cs file in second application.

    Wednesday, November 14, 2018 10:13 AM
  • User753101303 posted

    So it is about sharing an authentication cookie accross applications in a domain ? In your CookieAuthenticationOptions you would have CookieDomain=".mydomain.com" to scope the cookie to the whole domain and you'll need to use the same machinekey in all apps so that it can be decrypted.

    Edit: try maybe https://www.hanselman.com/blog/SharingAuthorizationCookiesBetweenASPNET4xAndASPNETCore10.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 11:55 AM
  • User611346789 posted

    Thanks for your help. I have added CookieAutheticatioOptions in both project. Suppose my primary project is project A and secondary project is project B. When i have started project A CookieAuthenticationOptions loaded correctly from Startup.cs class but unfortunately in Project B startup.cs class is not invoked. That means project B is not loading the CookieAuthenticationOptions. I have added Asp.Net Identity later in Project B that's why may b i missed some configuration that's why Startup.cs class is not invoked. Can you please tell me what will be the possible reason for not invoking Startup.cs class in Project B ?? Thanks why when i am starting project B then that says error : IIS access Denied

    Thursday, November 15, 2018 3:56 AM
  • User611346789 posted

    I have done that. But now a new problem start agian.

    app.UseCookieAuthentication(new CookieAuthenticationOptions ()
    {
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    ExpireTimeSpan = TimeSpan.MaxValue,
    LoginPath = new PathString("http://localhost:8864/Home/login"),
    CookieName = "cookiename",
    CookieDomain = ".localhost",
    SlidingExpiration = true
    });

    above code is in Project B but LoginPath is not allow to use a url. How can i use Url for Redirection like Forms Authentication ??

    Thursday, November 15, 2018 4:59 AM