Implement OAuth 2.0 in web API using .net 6 - OWIN for token generation

Mahantesh Ambiger 6 Reputation points
2022-01-19T22:49:30.037+00:00

I want to implement token based authentication in .net web api for the clients. I am stuck as IAppBuilder is not available in .net 6. Can you please point me to articles/code where it is implemented for apis developed using .net core and .net 6?

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-01-20T02:31:02.4+00:00

    Hi @Mahantesh Ambiger ,

    If you want to add authentication for oauth in asp.net core 6, I suggest you could refer to below cods:

    Modify the program.cs:

    builder.Services.AddAuthentication().AddOAuth("Oauth", options =>  
    {  
        // When a user needs to sign in, they will be redirected to the authorize endpoint  
        options.AuthorizationEndpoint ="";  
       
        // scopes when redirecting to the authorization endpoint  
        options.Scope.Add("openid");  
        options.Scope.Add("profile");  
        options.Scope.Add("email");  
      
        options.ClientSecret = "";  
      
    });  
    
    0 comments No comments

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.