Results 1 to 7 of 7

Thread: .NET 6 Scaffold Identity Without UI

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,304

    .NET 6 Scaffold Identity Without UI

    Do you have any recommendations for scaffolding the Identity authorization/authentication guts without including any of the existing UI?

    For background, I have a .NET 6 web API project, a .NET 6 class project (as a domain/service layer), a .NET 4.8 database project, and an Ionic/Angular web application.

    I want to secure my web API so that I can easily add the authenticate attributes to my controller routes.
    "Code is like humor. When you have to explain it, it’s bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,304

    Re: .NET 6 Scaffold Identity Without UI

    I will shamelessly bump this.
    "Code is like humor. When you have to explain it, it’s bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,437

    Re: .NET 6 Scaffold Identity Without UI

    Wish I could help you with this. I've been meaning to dive deep into ASP.Net and web development for a long time now but I just haven't gotten around to it yet. I've dabble in it here and there but not enough to confidently advise anyone about it.

    You can try having a conversation with ChatGPT about it, it might help guide you in the right direction. I've found it immensely helpful in learning new stuff as it can narrow down topics specifically to what you want. From there you can Google specifics based on what it tells you.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    526

    Re: .NET 6 Scaffold Identity Without UI

    You have to create List(Of Claim) that you can use in authorization attribute ("admin", "manager", "operations"), ClaimsIdentity with the claims list and ClaimsPrincipal that uses the claims identity.

    Then use HttpContext.SignInAsync() and the claims principal object to sign-in. You can use your own users data management instead of the template one generated by the scaffolding.

    In the login/users controller return generated session token (e.g. GUID) that you can use to recognize the user - you have to keep somewhere the list of active tokens to users relation.

    If you need to check if user is authenticated, use HttpContext.User.Identity.IsAuthenticated.

    To sign-out user (or API client) - use HttpContext.SignOutAsync()

    Finally, try not to pass the user login name and password outside the login process. Use tokens where you can identify the user.

  5. #5

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,304

    Re: .NET 6 Scaffold Identity Without UI

    Quote Originally Posted by Niya View Post
    You can try having a conversation with ChatGPT about it, it might help guide you in the right direction. I've found it immensely helpful in learning new stuff as it can narrow down topics specifically to what you want. From there you can Google specifics based on what it tells you.
    Yeah, the issue is that there are approximately 50 million ways to implement auth in .NET core so the information its giving is too vague.
    "Code is like humor. When you have to explain it, it’s bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,304

    Re: .NET 6 Scaffold Identity Without UI

    Quote Originally Posted by peterst View Post
    You have to create List(Of Claim) that you can use in authorization attribute ("admin", "manager", "operations"), ClaimsIdentity with the claims list and ClaimsPrincipal that uses the claims identity.

    Then use HttpContext.SignInAsync() and the claims principal object to sign-in. You can use your own users data management instead of the template one generated by the scaffolding.

    In the login/users controller return generated session token (e.g. GUID) that you can use to recognize the user - you have to keep somewhere the list of active tokens to users relation.

    If you need to check if user is authenticated, use HttpContext.User.Identity.IsAuthenticated.

    To sign-out user (or API client) - use HttpContext.SignOutAsync()

    Finally, try not to pass the user login name and password outside the login process. Use tokens where you can identify the user.
    To be honest, I was hoping more for a link that provides me with a step by step walkthrough without relying on using one of the templates because (by design) I selected an empty web API project template to begin with.
    "Code is like humor. When you have to explain it, it’s bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    526

    Re: .NET 6 Scaffold Identity Without UI

    I am the link And I described step by step (or line by line if it is translated to code) what I did for simple login management.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width