From 78ff179c3bc77626c454b71c7734dd61a2517da2 Mon Sep 17 00:00:00 2001 From: OpenIddict Bot <32257313+openiddict-bot@users.noreply.github.com> Date: Wed, 4 Jul 2018 11:39:01 +0000 Subject: [PATCH] Update the documentation pages --- guide/getting-started.html | 152 ++++++++++++++++++++----------------- manifest.json | 2 +- 2 files changed, 84 insertions(+), 70 deletions(-) diff --git a/guide/getting-started.html b/guide/getting-started.html index 9e94771..31456fe 100644 --- a/guide/getting-started.html +++ b/guide/getting-started.html @@ -75,20 +75,9 @@
  • Have an existing project or create a new one: when creating a new project using Visual Studio's default ASP.NET Core template, using individual user accounts authentication is strongly recommended. When updating an existing project, you must provide your own AccountController to handle the registration process and the authentication flow.

  • -
  • Add the appropriate MyGet repositories to your NuGet sources. This can be done by adding a new NuGet.Config file at the root of your solution:

    -
    <?xml version="1.0" encoding="utf-8"?>
    -<configuration>
    -<packageSources>
    -    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
    -    <add key="aspnet-contrib" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
    -</packageSources>
    -</configuration>
    -
  • -
  • Update your .csproj file to reference AspNet.Security.OAuth.Validation and the OpenIddict packages:

    -
    <PackageReference Include="AspNet.Security.OAuth.Validation" Version="2.0.0-*" />
    -<PackageReference Include="OpenIddict" Version="2.0.0-*" />
    +
  • Update your .csproj file to reference the OpenIddict packages:

    +
    <PackageReference Include="OpenIddict" Version="2.0.0-*" />
     <PackageReference Include="OpenIddict.EntityFrameworkCore" Version="2.0.0-*" />
    -<PackageReference Include="OpenIddict.Mvc" Version="2.0.0-*" />
     
  • Configure the OpenIddict services in Startup.ConfigureServices:

    public void ConfigureServices(IServiceCollection services)
    @@ -111,38 +100,38 @@
             .AddEntityFrameworkStores<ApplicationDbContext>()
             .AddDefaultTokenProviders();
     
    -    // Register the OAuth2 validation handler.
    -    services.AddAuthentication()
    -        .AddOAuthValidation();
    -
         // Register the OpenIddict services.
    -    // Note: use the generic overload if you need
    -    // to replace the default OpenIddict entities.
    -    services.AddOpenIddict(options =>
    -    {
    -        // Register the Entity Framework stores.
    -        options.AddEntityFrameworkCoreStores<ApplicationDbContext>();
    +    services.AddOpenIddict()
    +        .AddCore(options =>
    +        {
    +            // Configure OpenIddict to use the Entity Framework Core stores and entities.
    +            options.UseEntityFrameworkCore()
    +                   .UseDbContext<ApplicationDbContext>();
    +        })
     
    -        // 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.AddMvcBinders();
    +        .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 token endpoint (required to use the password flow).
    -        options.EnableTokenEndpoint("/connect/token");
    +            // Enable the token endpoint (required to use the password flow).
    +            options.EnableTokenEndpoint("/connect/token");
     
    -        // Allow client applications to use the grant_type=password flow.
    -        options.AllowPasswordFlow();
    +            // Allow client applications to use the grant_type=password flow.
    +            options.AllowPasswordFlow();
     
    -        // During development, you can disable the HTTPS requirement.
    -        options.DisableHttpsRequirement();
    -    });
    +            // During development, you can disable the HTTPS requirement.
    +            options.DisableHttpsRequirement();
    +
    +            // Accept token requests that don't specify a client_id.
    +            options.AcceptAnonymousClients();
    +        })
    +
    +        .AddValidation();
     }
    -

    Note: for more information about the different options and configurations available, check out -Configuration and options -in the project wiki.

    -
    -
  • +
  • Make sure the authentication middleware is registered before all the other middleware, including app.UseMvc():

    public void Configure(IApplicationBuilder app)
     {
    @@ -162,53 +151,78 @@ in the project wiki.

    // to replace the default OpenIddict entities. options.UseOpenIddict(); }); -

    Note: if you change the default entity primary key (e.g. to int or Guid instead of string), make sure to use the services.AddOpenIddict() extension accepting a TKey generic argument and use the generic options.UseOpenIddict<TKey>() overload.

    -
    -
  • -
  • Create your own authorization controller:

    +
  • + +

    Note: if you change the default entity primary key (e.g. to int or Guid instead of string), make sure you use the options.ReplaceDefaultEntities<TKey>() core extension accepting a TKey generic argument and use the generic options.UseOpenIddict<TKey>() overload to configure Entity Framework Core to use the specified key type:

    +
    services.AddOpenIddict()
    +    .AddCore(options =>
    +    {
    +        // Configure OpenIddict to use the default entities with a custom key type.
    +        options.UseEntityFrameworkCore()
    +               .UseDbContext<ApplicationDbContext>()
    +               .ReplaceDefaultEntities<Guid>();
    +    });
    +
    +services.AddDbContext<ApplicationDbContext>(options =>
    +{
    +    // Configure the context to use Microsoft SQL Server.
    +    options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]);
    +
    +    options.UseOpenIddict<Guid>();
    +});
    +
    +

    To support the password or the client credentials flow, you must provide your own token endpoint action. To enable authorization code/implicit flows support, you'll similarly have to create your own authorization endpoint action and your own views/view models.

    The Mvc.Server sample comes with an AuthorizationController that supports both the password flow and the authorization code flow and that you can easily reuse in your application.

    - +