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.

UX improvements in OpenIddict RC3

See original GitHub issue

In this release, we focused on reworking the OpenIddict registration APIs to offer a better user experience.

As part of this change, we split the OpenIddict services into three areas - Core, Server and Validation - and the IServiceCollection APIs have been updated to reflect that:

image

Each specialized builder only exposes the options that are relevant to its specific area:

image

image

Of course, the calls to AddCore(), AddServer() and AddValidation() can be chained:

services.AddOpenIddict()

    // Register the OpenIddict core services.
    .AddCore(options =>
    {
        // Register the Entity Framework stores and models.
        options.UseEntityFrameworkCore()
               .UseDbContext<ApplicationDbContext>();
    })

    // Register the OpenIddict server handler.
    .AddServer(options =>
    {
        // Register the ASP.NET Core MVC binder used by OpenIddict.
        // Note: if you don't call this method, you won't be able to
        // bind OpenIdConnectRequest or OpenIdConnectResponse parameters.
        options.UseMvc();

        // Enable the authorization, logout, token and userinfo endpoints.
        options.EnableAuthorizationEndpoint("/connect/authorize")
               .EnableLogoutEndpoint("/connect/logout")
               .EnableTokenEndpoint("/connect/token")
               .EnableUserinfoEndpoint("/api/userinfo");

        // Note: the Mvc.Client sample only uses the code flow and the password flow, but you
        // can enable the other flows if you need to support implicit or client credentials.
        options.AllowAuthorizationCodeFlow()
               .AllowPasswordFlow()
               .AllowRefreshTokenFlow();

        // During development, you can disable the HTTPS requirement.
        options.DisableHttpsRequirement();
    })

    // Register the OpenIddict validation handler.
    // Note: the OpenIddict validation handler is only compatible with the
    // default token format or with reference tokens and cannot be used with
    // JWT tokens. For JWT tokens, use the Microsoft JWT bearer handler.
    .AddValidation();

Introducing these specialized builders was also a great opportunity to revisit how the OpenIddict entities are registered. In the RC2 bits, this is controlled by the services.AddOpenIddict<...>() method, that determines which entities are used depending on the overload.

In RC3, the generic services.AddOpenIddict<...>() methods have been removed and replaced by a more explicit pattern:

image


In this release, we also made debugging easier by adding custom exception messages instead of relying on the rather cryptic DI-related messages thrown by ASP.NET Core.

If you forget to register stores, you’ll now get a much clearer exception:

System.InvalidOperationException : No application store has been registered in the dependency injection container.
To register the Entity Framework Core stores, reference the 'OpenIddict.EntityFrameworkCore' package and call 'services.AddOpenIddict().AddCore().UseEntityFrameworkCore()'.
To register a custom store, create an implementation of 'IOpenIddictApplicationStore' and use 'services.AddOpenIddict().AddCore().AddApplicationStore()' to add it to the DI container.

If you use an entity that is not compatible with the underlying store, you’ll also get a better exception:

System.InvalidOperationException : The specified application type is not compatible with the Entity Framework Core stores.
When enabling the Entity Framework Core stores, make sure you use the built-in 'OpenIddictApplication' entity (from the 'OpenIddict.EntityFrameworkCore.Models' package) or a custom entity that inherits from the generic 'OpenIddictApplication' entity.

Similarly, if you forget to register the core services when enabling the server or validation handlers, you’ll get an exception:

System.InvalidOperationException : The core services must be registered when enabling the server handler.
To register the OpenIddict core services, use 'services.AddOpenIddict().AddCore()'.
System.InvalidOperationException : The core services must be registered when enabling reference tokens support.
To register the OpenIddict core services, use 'services.AddOpenIddict().AddCore()'.

Hope you’ll appreciate these changes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
hoangdovancommented, Apr 27, 2018

So tired with openiddict always change like this, my project broken because of this change. Why openiddict still rc after so long time and cannot be stable with official release version?

2reactions
kinosangcommented, Apr 27, 2018

@hoangdovan as @PinpointTownes said, choose the nightly builds means you accept the risk.

Most of projects have broken changes in nightly builds. It’s unusual to upgrade packages (even rc, rtm or stable version) without having a look at the release note for production environment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing advanced scenarios using the new OpenIddict ...
In this post, discover how to leverage the events model introduced in OpenIddict RC3 to implement advanced features.
Read more >
OpenIddict RC3 is out | Kévin Chalet's blog
In this release, we focused on reworking the OpenIddict registration APIs to offer a better user experience. As part of this change, we...
Read more >
v12.0.0
Changes in RC3. Fixed the namespace of PageModel (Breaking) - 14296; Added support for specifying package versions through assembly version ...
Read more >
OpenIddict
OpenIddict aims at providing a versatile solution to implement OpenID Connect client, server and token validation support in any ASP.
Read more >
c# - OpenIddict problems
In OpenIddict RC2, all the options used to be grouped. services. ... DisableHttpsRequirement(); }); // In OpenIddict RC3, the options are ...
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