How to build WebAPI 2 with Oauth

Mr Edge 221 Reputation points
2023-04-02T09:36:16.78+00:00

I'm using .Net 4.8 but also considering .Net 6. I would like to build a API which allows people to connect to and receive/ insert data into our database. I've managed create a basic WebAPI but I don't know how to secure it using oauth2 which I think is the proper way to introduce some form of username and password in order to create/retrieve tokens? Does anyone know if there are libraries I can use to carry this out? I'm using RestSharp but would be great if someone could give some guidance. I read owasp which I think is where I need to meet since criteria but became confused. Would be great to if someone could give me some guidance to introduce a username password to my website.

Developer technologies ASP.NET Other
Developer technologies C#
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2023-04-02T11:53:54.2466667+00:00
    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-04-02T15:43:30.3+00:00

    In the webapi you enable jwt tokens for authentication with Microsoft identity. You will need to configure the oauth setting so it can validate the token.

    in the client code you will need to get an oauth token. Hiw this is done depends on the oauth provider an the oauth flow required.

    If a browser is calling you webapi via JavaScript, then you probably use you will want a JavaScript library.

    If the client is c# code, then typically you will use a client secret, and can call the authentication provider directly of via a sdk.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.