question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Authenticating default token type in separate project from where "/connect/token" endpoint is

See original GitHub issue

Hello, I’ve been struggling with this for quite a few long days now so I figure that it’s time to reach out for help as I am working against a deadline and don’t have anyone inside my company to go to. It’s an issue that I just can’t seem to wrap my head around after doing a lot of research but may be obvious to someone who has done it before and will be easy to explain.

The solution I am working with has two main projects, I’ll refer to them as Portal and API which run on ‘localhost:5000’ and ‘localhost:5001’ respectively. We have openiddict middleware set up for Portal, which utilizes the “/connect/token” endpoint. When a user visits the site, they click login and if they have valid credentials they are signed in and issued an access token which is saved in the front end. The middleware is set up in Portal’s ‘Startup.cs’ as follows:

// Register the OpenIddict services.
            services.AddOpenIddict(options =>
            {
                options.AddEntityFrameworkCoreStores<ApplicationDbContext>();
                options.AddMvcBinders();
                options.EnableTokenEndpoint("/connect/token");
                options.AllowPasswordFlow();
                options.AllowRefreshTokenFlow();
                options.DisableHttpsRequirement();
                //options.AddSigningKey(new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(Configuration["STSKey"])));
            });

After successful login, the user is redirected to the home page which makes several calls to controllers within API, a separate project. I would like to add the [Authorize] header to these controllers so that they are secured but I can’t figure out what middleware to add in the API ‘Startup.cs’ so that it authenticates incoming bearer tokens, which were generated from Portal, against the same middleware set up in Portal. From my research I am fairly certain that something along the lines of

services.AddAuthentication().AddSpecificTokenValidation();

in the ConfigureServices() method then in the Configure() method:

app.UseAuthentication();

but I am not sure where to go from there.

I am somewhat familiar with the concept of Authority and Audience and feel like those need to come in to play but I am unsure where those are being set in the token generation process or if they even need to be set at all. Also, what “type” of token validation should be used for the default tokens generated using openiddict? Any help would be greatly appreciated!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
slimwizardcommented, Oct 5, 2018

In the ConfigureServices method you need to ‘add authentication’ and in Configure method you need to ‘use authentication’. These are methods that can be called on your services and app objects. You will also need to specify what type of authentication scheme to use in the .addAuthentication() method. If you look at the stack overflow link that is posted, you will notice that the asker already has this setup in his Startup.cs file. If you are wanting to use the default scheme then you should be able to use the same lines of code. @TheElectricCo

0reactions
TheElectricCocommented, Oct 18, 2018

Thanks, it works 😃 Sorry for the late comment!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Token Authentication in ASP.NET Core 2.0
Token authentication is the process of attaching a token (sometimes called an access token or a bearer token) to HTTP requests in order...
Read more >
How to get an access token with Authorization Code Grant
This topic demonstrates how to generate an access token manually using Authorization Code Grant authentication or with a refresh token. In the Authorization...
Read more >
Secure a Web API with Individual Accounts and Local ...
The HostAuthenticationFilter class enables authentication using bearer tokens. The SuppressDefaultHostAuthentication method tells Web API to ...
Read more >
Authenticate an IMAP, POP or SMTP connection using OAuth
Learn how to use OAuth authentication with your IMAP, POP, and SMTP ... refresh tokens from the Microsoft identity platform token endpoint.
Read more >
OAuth 2.0 token endpoint
Clients obtain access and ID tokens from the token endpoint in exchange for an OAuth ... Basic authentication is the default method for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found