Skip to content

r1-prototype-studies/ASP.NET_Authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#ASP.NET Authentication

OAuth Authentication

Notes

  • Install necessary Nugets
  • Create the necessary tables and stored procedures
  • [Authorize] attribute should be added to controller
  • Add authentication configuration in the startup.cs
  // Web API configuration and services  
  // Configure Web API to use only bearer token authentication.  
  config.SuppressDefaultHostAuthentication();  
  config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));  
  • Json format for the response
  // WebAPI when dealing with JSON & JavaScript!  
  // Setup json serialization to serialize classes to camel (std. Json format)  
  var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;  
  formatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); 
  • Implementation authentication in start.auth.cs
  • Implementation authentication provider in AppOAuthProvider

Nugets Installation

  • Microsoft.Owin.Security.OAuth
  • Microsoft.Owin.Cors
  • Microsoft.AspNet.WebApi.Core
  • Microsoft.AspNet.WebApi.Owin
  • Microsoft.Owin.Security.Cookies
  • Microsoft.AspNet.Identity.Core
  • Microsoft.AspNet.Identity.Owin
  • Microsoft.Owin.Host.SystemWeb

Postman testing

Access Token Generation Access Token Generation

WebApi Authentication WebApi Authentication

References

  1. https://www.c-sharpcorner.com/article/asp-net-mvc-oauth-2-0-rest-web-api-authorization-using-database-first-approach/
  2. https://docs.microsoft.com/en-us/previous-versions/aspnet/dn308223(v=vs.113)?redirectedfrom=MSDN

Access OAuth REST Web API

Notes

  • Get Authorization code using the client credentials
  • Parse the result and get access token
  • Send the access token as an authourization header

Nugets

  • Newtonsoft.Json

References

  1. https://www.c-sharpcorner.com/article/c-sharp-net-access-oauth-rest-web-api-method/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors