How to Add authentication for self hosted web API?

165 Views Asked by At

I have a self hosted Web API in console project. I need to authroize the user on role based or domain based.

How can i achieve it.

Sample Code :

-- Here how can i implement the Authentication and authorization --

public class Sample : ODataController
 {
[EnableQuery]
public IHttpActionResult Get(ODataQueryOptions<APINAME> opts)
                        {

                         }
}
1

There are 1 best solutions below

2
On

You should use the both. In AD you set user groups and you assign specific permission to groups.

You need to keep in mind that users come and go but groups can stay definitely

I've worked on this kind of project 8 years ago.

  • The frontend was writing everything in a database (MS-SQL)
  • A windows service was querying a Status table which was reporting db activities
  • That windows service was applying the ACL according to the Status refs

We were in Windows Server environment, I was using CMD (MS DOS ICACLS)

In .Net or from Powershell or from MS DOS you can apply ACLs

Some resources

CACLS before ICACLS which seems more complex

An illustrations in Windows where you can see the changes you made

This other answer may help you