mirror of
https://gitee.com/dcren/openiddict-documentation.git
synced 2025-09-19 10:07:58 +08:00
Update the documentation pages
This commit is contained in:
258
guides/choosing-the-right-flow.html
Normal file
258
guides/choosing-the-right-flow.html
Normal file
@@ -0,0 +1,258 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE]><![endif]-->
|
||||
<html>
|
||||
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Choosing the right flow </title>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="title" content="Choosing the right flow ">
|
||||
<meta name="generator" content="docfx 2.56.7.0">
|
||||
|
||||
<link rel="shortcut icon" href="../images/favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/night-owl.min.css">
|
||||
<link rel="stylesheet" href="../styles/colors.css">
|
||||
<link rel="stylesheet" href="../styles/discord.css">
|
||||
<link rel="stylesheet" href="../styles/main.css">
|
||||
<meta property="docfx:navrel" content="../toc.html">
|
||||
<meta property="docfx:tocrel" content="toc.html">
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="top-navbar">
|
||||
|
||||
<a href="javascript:void(0);" class="burger-icon" onclick="toggleMenu()">
|
||||
<svg name="Hamburger" style="vertical-align: middle;" width="24" height="24" viewbox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M20 6H4V9H20V6ZM4 10.999H20V13.999H4V10.999ZM4 15.999H20V18.999H4V15.999Z"></path></svg>
|
||||
</a>
|
||||
|
||||
|
||||
<a class="brand" href="../index.html">
|
||||
<img src="../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
|
||||
<div id="blackout" class="blackout" onclick="toggleMenu()"></div>
|
||||
|
||||
<nav id="sidebar" role="navigation">
|
||||
|
||||
<div class="sidebar">
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a class="brand" href="../index.html">
|
||||
<img src="../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
<div id="navbar">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sidebar-item-separator"></div>
|
||||
|
||||
|
||||
<div id="sidetoggle">
|
||||
<div id="sidetoc"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<span>Generated by <strong>DocFX</strong></span>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main-panel">
|
||||
|
||||
<div role="main" class="hide-when-search">
|
||||
|
||||
|
||||
<div class="subnav navbar navbar-default">
|
||||
<div class="container hide-when-search" id="breadcrumb">
|
||||
<ul class="breadcrumb">
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<article class="content wrap" id="_content" data-uid="">
|
||||
<h1 id="choosing-the-right-flow">Choosing the right flow</h1>
|
||||
|
||||
<p>OpenIddict offers built-in support for all the standard flows defined by the
|
||||
<a href="https://tools.ietf.org/html/rfc6749">OAuth 2.0</a> and <a href="https://openid.net/specs/openid-connect-core-1_0.html">OpenID Connect</a> core specifications:
|
||||
<a href="https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth">the authorization code flow</a>,
|
||||
<a href="https://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth">the implicit flow</a>,
|
||||
<a href="https://openid.net/specs/openid-connect-core-1_0.html#HybridFlowAuth">the hybrid flow</a> (which is basically a mix between the first two flows),
|
||||
<a href="https://tools.ietf.org/html/rfc6749#section-4.3">the resource owner password credentials grant</a> and
|
||||
<a href="https://tools.ietf.org/html/rfc6749#section-4.4">the client credentials grant</a>.</p>
|
||||
<p>While not specific to OpenIddict, choosing the best flow(s) for your application is an <strong>important prerequisite</strong>
|
||||
when implementing your own authorization server ; so here's a quick overview of the different OAuth 2.0/OpenID Connect flows:</p>
|
||||
<hr>
|
||||
<h2 id="non-interactive-flows">Non-interactive flows</h2>
|
||||
<h3 id="resource-owner-password-credentials-flow-not-recommended-for-new-applications">Resource owner password credentials flow (not recommended for new applications)</h3>
|
||||
<p>Directly inspired by <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">basic authentication</a>, the resource owner password credentials grant
|
||||
(abbreviated <em>ROPC</em>) is conceptually <strong>the simplest OAuth 2.0 flow</strong>: the client application asks the user his username/password, sends a token request
|
||||
to the authorization server with the user credentials (and depending on the client authentication policy defined by the authorization server,
|
||||
its own client credentials) and gets back an access token it can use to retrieve the user's resources.</p>
|
||||
<p><img src="choosing-the-right-flow/resource-owner-password-flow.png" alt="Resource owner password credentials flow"></p>
|
||||
<pre><code class="lang-http">POST /connect/token HTTP/1.1
|
||||
Host: server.example.com
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
grant_type=password&username=johndoe&password=A3ddj3w
|
||||
</code></pre><pre><code class="lang-http">HTTP/1.1 200 OK
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
Cache-Control: no-store
|
||||
Pragma: no-cache
|
||||
|
||||
{
|
||||
"access_token":"2YotnFZFEjr1zCsicMWpAA",
|
||||
"token_type":"bearer",
|
||||
"expires_in":3600
|
||||
}
|
||||
</code></pre><div class="CAUTION"><h5>Caution</h5><p>This flow is <strong>not recommended by the OAuth 2.0 specification</strong> as it's the only grant type where <strong>the user password is directly exposed to the client application</strong>,
|
||||
which breaks the principle of least privilege and <strong>makes it unsuitable for third-party client applications that can't be fully trusted by the authorization server</strong>.</p>
|
||||
<p>While popular and trivial to implement (as it doesn't involve any redirection or consent form and unlike interactive flows, doesn't require implementing
|
||||
cross-site request forgery (XSRF) countermeasures to prevent session fixation attacks), <strong>its use in new applications is not recommended</strong>. Instead,
|
||||
users are encouraged to use the authorization code flow, that doesn't expose passwords to client applications and is not limited to password authentication.</p>
|
||||
</div>
|
||||
<!-- more -->
|
||||
<hr>
|
||||
<h3 id="client-credentials-grant-recommended-for-machine-to-machine-communication">Client credentials grant (recommended for machine-to-machine communication)</h3>
|
||||
<p>The client credentials grant is almost identical to the resource owner password credentials grant, except it's been specifically designed for <strong>client-to-server scenarios</strong>
|
||||
(no user is involved in this flow): the client application sends a token request containing its credentials and gets back an access token it can use to query its own resources.</p>
|
||||
<p><img src="choosing-the-right-flow/client-credentials-flow.png" alt="Client credentials flow"></p>
|
||||
<pre><code class="lang-http">POST /connect/token HTTP/1.1
|
||||
Host: server.example.com
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
grant_type=client_credentials&client_id=s6BhdRkqt3&client_secret=gX1fBat3bV
|
||||
</code></pre><pre><code class="lang-http">HTTP/1.1 200 OK
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
Cache-Control: no-store
|
||||
Pragma: no-cache
|
||||
|
||||
{
|
||||
"access_token":"2YotnFZFEjr1zCsicMWpAA",
|
||||
"token_type":"bearer",
|
||||
"expires_in":3600
|
||||
}
|
||||
</code></pre><div class="NOTE"><h5>Note</h5><p>Unlike the resource owner password credentials grant, <strong>client authentication is not optional</strong> when using the client credentials grant and
|
||||
<strong>OpenIddict will always reject unauthenticated token requests</strong>, <a href="https://tools.ietf.org/html/rfc6749#section-4.4.2">as required by the OAuth 2.0 specification</a>.</p>
|
||||
<p>This means that <strong>you CAN'T use the client credentials grant with public applications</strong> like browser,
|
||||
mobile or desktop applications, as they are not able to keep their credentials secret.</p>
|
||||
</div>
|
||||
<hr>
|
||||
<h2 id="interactive-flows">Interactive flows</h2>
|
||||
<h3 id="authorization-code-flow-recommended-for-new-applications">Authorization code flow (recommended for new applications)</h3>
|
||||
<p>While the authorization code flow is probably the most complicated flow (as it involves both <strong>user-agent redirections and backchannel communication</strong>), it's
|
||||
<strong>the recommended flow for any scenario involving end users, whether they log in using a password, a PIN, a smart card or even an external provider</strong>.
|
||||
In return for its complexity, this flow has a great advantage when used in server-side applications: the <code>access_token</code> cannot be intercepted by the user agent.</p>
|
||||
<p>There are basically 2 steps in the authorization code flow: the authorization request/response and the token request/response.</p>
|
||||
<p><img src="choosing-the-right-flow/authorization-code-flow.png" alt="Authorization code flow"></p>
|
||||
<ul>
|
||||
<li><strong>Step 1: the authorization request</strong></li>
|
||||
</ul>
|
||||
<p>In this flow, the client application always initiates the authentication process by generating an authorization request including
|
||||
the mandatory <code>response_type=code</code> parameter, its <code>client_id</code>, its <code>redirect_uri</code> and optionally, a <code>scope</code> and a <code>state</code> parameter
|
||||
<a href="https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest">that allows flowing custom data and helps mitigate XSRF attacks</a>.</p>
|
||||
<div class="NOTE"><h5>Note</h5><p>In most cases, the client application will simply return a 302 response with a <code>Location</code> header to redirect the user agent to the authorization endpoint,
|
||||
but depending on the OpenID Connect client you're using, POST requests might also be supported to allow you to send large authorization requests.
|
||||
This feature <a href="https://github.com/aspnet/Security/pull/392">is usually implemented using an auto-post HTML form</a>.</p>
|
||||
</div>
|
||||
<pre><code class="lang-http">HTTP/1.1 302 Found
|
||||
Location: https://server.example.com/authorize?response_type=code&client_id=s6BhdRkqt3&state=af0ifjsldkj&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb
|
||||
</code></pre><pre><code class="lang-http">GET /connect/authorize?response_type=code&client_id=s6BhdRkqt3&state=af0ifjsldkj&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb HTTP/1.1
|
||||
Host: server.example.com
|
||||
</code></pre><p>The way the identity provider handles the authorization request is implementation-specific but in most cases, a consent form
|
||||
is displayed to ask the user if he or she agrees to share his/her personal data with the client application.</p>
|
||||
<p><img src="choosing-the-right-flow/consent-form.png" alt="Consent form"></p>
|
||||
<p>When the consent is given, the user agent is redirected back to the client application with <strong>a unique and short-lived token</strong>
|
||||
named <em>authorization code</em> that the client will be able to exchange with an access token by sending a token request.</p>
|
||||
<pre><code class="lang-http">HTTP/1.1 302 Found
|
||||
Location: https://client.example.org/cb?code=SplxlOBeZQQYbYS6WxSbIA&state=af0ifjsldkj
|
||||
</code></pre><div class="WARNING"><h5>Warning</h5><p>To prevent XSRF/session fixation attacks, <strong>the client application MUST ensure that the <code>state</code> parameter returned by the identity provider
|
||||
corresponds to the original <code>state</code></strong> and stop processing the authorization response if the two values don't match.
|
||||
<a href="https://tools.ietf.org/html/rfc6749#section-10.12">This is usually done by generating a non-guessable string and a corresponding correlation cookie</a>.</p>
|
||||
</div>
|
||||
<ul>
|
||||
<li><strong>Step 2: the token request</strong></li>
|
||||
</ul>
|
||||
<p>When the client application gets back an authorization code, it must immediately reedem it for an access token by sending a <code>grant_type=authorization_code</code> token request.</p>
|
||||
<div class="NOTE"><h5>Note</h5><p>To help the identity provider <a href="https://tools.ietf.org/html/rfc6819#section-4.4.1.7">mitigate counterfeit clients attacks</a>, the original <code>redirect_uri</code> must also be sent.</p>
|
||||
<p>If the client application is a confidential application (i.e an application that has been assigned client credentials), authentication is required.</p>
|
||||
</div>
|
||||
<pre><code class="lang-http">POST /connect/token HTTP/1.1
|
||||
Host: server.example.com
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb&client_id=s6BhdRkqt3&client_secret=gX1fBat3bV&scope=openid
|
||||
</code></pre><pre><code class="lang-http">HTTP/1.1 200 OK
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
Cache-Control: no-store
|
||||
Pragma: no-cache
|
||||
|
||||
{
|
||||
"access_token":"2YotnFZFEjr1zCsicMWpAA",
|
||||
"token_type":"bearer",
|
||||
"expires_in":3600
|
||||
}
|
||||
</code></pre><div class="NOTE"><h5>Note</h5><p>To increase security, additional parameters such as <code>code_challenge</code> and <code>code_challenge_method</code> can be specified to bind the authorization code
|
||||
that will be returned by the authorization endpoint to the original authorization request. This mechanism is known as
|
||||
<a href="../configuration/proof-key-for-code-exchange.html">Proof Key for Code Exchange</a> and is fully supported by OpenIddict. </p>
|
||||
</div>
|
||||
<hr>
|
||||
<h3 id="implicit-flow-not-recommended-for-new-applications">Implicit flow (not recommended for new applications)</h3>
|
||||
<p>The implicit flow is similar to the authorization code flow, <strong>except there's no token request/response step</strong>: the access token is directly returned
|
||||
to the client application as part of the authorization response in the URI fragment (or in the request form when using <code>response_mode=form_post</code>).</p>
|
||||
<p><img src="choosing-the-right-flow/implicit-flow.png" alt="Implicit flow"></p>
|
||||
<pre><code class="lang-http">GET /connect/authorize?response_type=token&client_id=s6BhdRkqt3&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb&scope=openid&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj HTTP/1.1
|
||||
Host: server.example.com
|
||||
</code></pre><pre><code class="lang-http">HTTP/1.1 302 Found
|
||||
Location: https://client.example.org/cb#access_token=SlAV32hkKG&token_type=bearer&expires_in=3600&state=af0ifjsldkj
|
||||
</code></pre><div class="CAUTION"><h5>Caution</h5><p>Initially designed for browser applications, this flow is inherently less secure than the authorization code flow and doesn't support
|
||||
<a href="https://tools.ietf.org/html/rfc7636">Proof Key for Code Exchange</a>. As such, using it in new applications is not recommended.</p>
|
||||
</div>
|
||||
<div class="WARNING"><h5>Warning</h5><p>To prevent XSRF/session fixation attacks, <strong>the client application MUST ensure that the <code>state</code> parameter returned by the identity provider
|
||||
corresponds to the original <code>state</code></strong> and stop processing the authorization response if the two values don't match.
|
||||
<a href="https://tools.ietf.org/html/rfc6749#section-10.12">This is usually done by generating a non-guessable string and a corresponding value stored in the local storage</a>.</p>
|
||||
<p>When using the implicit flow, <strong>the client application MUST also ensure that the access token was not issued
|
||||
to another application to prevent <a href="https://stackoverflow.com/a/17439317/542757">confused deputy attacks</a>.</strong>
|
||||
With OpenID Connect, this can be done by using <code>response_type=id_token token</code> and checking the <code>aud</code> claim
|
||||
of the JWT identity token, that must correspond or contain the <code>client_id</code> of the client application.</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="../styles/jquery.twbsPagination.js"></script>
|
||||
<script type="text/javascript" src="../styles/url.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/anchor-js/anchor.min.js"></script>
|
||||
<script type="text/javascript" src="../styles/docfx.js"></script>
|
||||
<script type="text/javascript" src="../styles/main.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
BIN
guides/choosing-the-right-flow/authorization-code-flow.png
Normal file
BIN
guides/choosing-the-right-flow/authorization-code-flow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
guides/choosing-the-right-flow/client-credentials-flow.png
Normal file
BIN
guides/choosing-the-right-flow/client-credentials-flow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
BIN
guides/choosing-the-right-flow/consent-form.png
Normal file
BIN
guides/choosing-the-right-flow/consent-form.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
guides/choosing-the-right-flow/implicit-flow.png
Normal file
BIN
guides/choosing-the-right-flow/implicit-flow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
guides/choosing-the-right-flow/resource-owner-password-flow.png
Normal file
BIN
guides/choosing-the-right-flow/resource-owner-password-flow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
300
guides/getting-started.html
Normal file
300
guides/getting-started.html
Normal file
@@ -0,0 +1,300 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE]><![endif]-->
|
||||
<html>
|
||||
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Getting started </title>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="title" content="Getting started ">
|
||||
<meta name="generator" content="docfx 2.56.7.0">
|
||||
|
||||
<link rel="shortcut icon" href="../images/favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/night-owl.min.css">
|
||||
<link rel="stylesheet" href="../styles/colors.css">
|
||||
<link rel="stylesheet" href="../styles/discord.css">
|
||||
<link rel="stylesheet" href="../styles/main.css">
|
||||
<meta property="docfx:navrel" content="../toc.html">
|
||||
<meta property="docfx:tocrel" content="toc.html">
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="top-navbar">
|
||||
|
||||
<a href="javascript:void(0);" class="burger-icon" onclick="toggleMenu()">
|
||||
<svg name="Hamburger" style="vertical-align: middle;" width="24" height="24" viewbox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M20 6H4V9H20V6ZM4 10.999H20V13.999H4V10.999ZM4 15.999H20V18.999H4V15.999Z"></path></svg>
|
||||
</a>
|
||||
|
||||
|
||||
<a class="brand" href="../index.html">
|
||||
<img src="../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
|
||||
<div id="blackout" class="blackout" onclick="toggleMenu()"></div>
|
||||
|
||||
<nav id="sidebar" role="navigation">
|
||||
|
||||
<div class="sidebar">
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a class="brand" href="../index.html">
|
||||
<img src="../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
<div id="navbar">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sidebar-item-separator"></div>
|
||||
|
||||
|
||||
<div id="sidetoggle">
|
||||
<div id="sidetoc"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<span>Generated by <strong>DocFX</strong></span>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main-panel">
|
||||
|
||||
<div role="main" class="hide-when-search">
|
||||
|
||||
|
||||
<div class="subnav navbar navbar-default">
|
||||
<div class="container hide-when-search" id="breadcrumb">
|
||||
<ul class="breadcrumb">
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<article class="content wrap" id="_content" data-uid="">
|
||||
<h1 id="getting-started">Getting started</h1>
|
||||
|
||||
<p><strong>To implement a custom OpenID Connect server using OpenIddict, the simplest option is to clone one of the official samples</strong> from the <a href="https://github.com/openiddict/openiddict-samples">openiddict-samples repository</a>.</p>
|
||||
<p>If you don't want to start from one of the recommended samples, you'll need to:</p>
|
||||
<ul>
|
||||
<li><p><strong>Install the <a href="https://www.microsoft.com/net/download">.NET Core 3.1 (or later) tooling</a></strong>.</p>
|
||||
</li>
|
||||
<li><p><strong>Have an existing project or create a new one</strong>: when creating a new project using Visual Studio's default ASP.NET Core template,
|
||||
using <strong>individual user accounts authentication</strong> is strongly recommended as it automatically includes the default ASP.NET Core Identity UI, based on Razor Pages.</p>
|
||||
</li>
|
||||
<li><p><strong>Update your <code>.csproj</code> file</strong> to reference the latest <code>OpenIddict</code> packages:</p>
|
||||
<pre><code class="lang-xml"><PackageReference Include="OpenIddict.AspNetCore" Version="3.1.1" />
|
||||
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.1.1" />
|
||||
</code></pre></li>
|
||||
<li><p><strong>Configure the OpenIddict core, server and validation services</strong> in <code>Startup.ConfigureServices</code>.
|
||||
Here's an example for the client credentials grant, used in machine-to-machine scenarios:</p>
|
||||
<pre><code class="lang-csharp">public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllersWithViews();
|
||||
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
{
|
||||
// Configure Entity Framework Core to use Microsoft SQL Server.
|
||||
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
|
||||
|
||||
// Register the entity sets needed by OpenIddict.
|
||||
// Note: use the generic overload if you need to replace the default OpenIddict entities.
|
||||
options.UseOpenIddict();
|
||||
});
|
||||
|
||||
services.AddOpenIddict()
|
||||
|
||||
// Register the OpenIddict core components.
|
||||
.AddCore(options =>
|
||||
{
|
||||
// Configure OpenIddict to use the Entity Framework Core stores and models.
|
||||
// Note: call ReplaceDefaultEntities() to replace the default entities.
|
||||
options.UseEntityFrameworkCore()
|
||||
.UseDbContext<ApplicationDbContext>();
|
||||
})
|
||||
|
||||
// Register the OpenIddict server components.
|
||||
.AddServer(options =>
|
||||
{
|
||||
// Enable the token endpoint.
|
||||
options.SetTokenEndpointUris("/connect/token");
|
||||
|
||||
// Enable the client credentials flow.
|
||||
options.AllowClientCredentialsFlow();
|
||||
|
||||
// Register the signing and encryption credentials.
|
||||
options.AddDevelopmentEncryptionCertificate()
|
||||
.AddDevelopmentSigningCertificate();
|
||||
|
||||
// Register the ASP.NET Core host and configure the ASP.NET Core options.
|
||||
options.UseAspNetCore()
|
||||
.EnableTokenEndpointPassthrough();
|
||||
})
|
||||
|
||||
// Register the OpenIddict validation components.
|
||||
.AddValidation(options =>
|
||||
{
|
||||
// Import the configuration from the local OpenIddict server instance.
|
||||
options.UseLocalServer();
|
||||
|
||||
// Register the ASP.NET Core host.
|
||||
options.UseAspNetCore();
|
||||
});
|
||||
|
||||
// Register the worker responsible of seeding the database with the sample clients.
|
||||
// Note: in a real world application, this step should be part of a setup script.
|
||||
services.AddHostedService<Worker>();
|
||||
}
|
||||
</code></pre></li>
|
||||
<li><p><strong>Make sure the ASP.NET Core authentication middleware is correctly registered at the right place</strong>:</p>
|
||||
<pre><code class="lang-csharp">public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(options =>
|
||||
{
|
||||
options.MapControllers();
|
||||
options.MapDefaultControllerRoute();
|
||||
});
|
||||
}
|
||||
</code></pre></li>
|
||||
<li><p><strong>Update your Entity Framework Core context registration to register the OpenIddict entities</strong>:</p>
|
||||
<pre><code class="lang-csharp">services.AddDbContext<ApplicationDbContext>(options =>
|
||||
{
|
||||
// Configure Entity Framework Core to use Microsoft SQL Server.
|
||||
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
|
||||
|
||||
// Register the entity sets needed by OpenIddict.
|
||||
// Note: use the generic overload if you need to replace the default OpenIddict entities.
|
||||
options.UseOpenIddict();
|
||||
});
|
||||
</code></pre><div class="NOTE"><h5>Note</h5><p>By default, the OpenIddict Entity Framework Core integration uses <code>string</code> as the default type for primary keys.
|
||||
To use a different type, read <a href="../integrations/entity-framework-core.html#use-a-custom-primary-key-type">Entity Framework Core integration : Use a custom primary key type</a>.</p>
|
||||
</div>
|
||||
</li>
|
||||
<li><p><strong>Create your own authorization controller:</strong>
|
||||
Implementing a custom authorization controller is required to allow OpenIddict to create tokens based on the identities and claims you provide.
|
||||
Here's an example for the client credentials grant:</p>
|
||||
<pre><code class="lang-csharp">public class AuthorizationController : Controller
|
||||
{
|
||||
private readonly IOpenIddictApplicationManager _applicationManager;
|
||||
|
||||
public AuthorizationController(IOpenIddictApplicationManager applicationManager)
|
||||
=> _applicationManager = applicationManager;
|
||||
|
||||
[HttpPost("~/connect/token"), Produces("application/json")]
|
||||
public async Task<IActionResult> Exchange()
|
||||
{
|
||||
var request = HttpContext.GetOpenIddictServerRequest();
|
||||
if (!request.IsClientCredentialsGrantType())
|
||||
{
|
||||
throw new NotImplementedException("The specified grant is not implemented.");
|
||||
}
|
||||
|
||||
// Note: the client credentials are automatically validated by OpenIddict:
|
||||
// if client_id or client_secret are invalid, this action won't be invoked.
|
||||
|
||||
var application = await _applicationManager.FindByClientIdAsync(request.ClientId) ??
|
||||
throw new InvalidOperationException("The application cannot be found.");
|
||||
|
||||
// Create a new ClaimsIdentity containing the claims that
|
||||
// will be used to create an id_token, a token or a code.
|
||||
var identity = new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, Claims.Name, Claims.Role);
|
||||
|
||||
// Use the client_id as the subject identifier.
|
||||
identity.AddClaim(Claims.Subject,
|
||||
await _applicationManager.GetClientIdAsync(application),
|
||||
Destinations.AccessToken, Destinations.IdentityToken);
|
||||
|
||||
identity.AddClaim(Claims.Name,
|
||||
await _applicationManager.GetDisplayNameAsync(application),
|
||||
Destinations.AccessToken, Destinations.IdentityToken);
|
||||
|
||||
return SignIn(new ClaimsPrincipal(identity),
|
||||
OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
|
||||
}
|
||||
}
|
||||
</code></pre></li>
|
||||
<li><p><strong>Register your client application</strong> (e.g from an <code>IHostedService</code> implementation):</p>
|
||||
<pre><code class="lang-csharp">public class Worker : IHostedService
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public Worker(IServiceProvider serviceProvider)
|
||||
=> _serviceProvider = serviceProvider;
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
|
||||
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
await context.Database.EnsureCreatedAsync();
|
||||
|
||||
var manager =
|
||||
scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();
|
||||
|
||||
if (await manager.FindByClientIdAsync("console") is null)
|
||||
{
|
||||
await manager.CreateAsync(new OpenIddictApplicationDescriptor
|
||||
{
|
||||
ClientId = "console",
|
||||
ClientSecret = "388D45FA-B36B-4988-BA59-B187D329C207",
|
||||
DisplayName = "My client application",
|
||||
Permissions =
|
||||
{
|
||||
Permissions.Endpoints.Token,
|
||||
Permissions.GrantTypes.ClientCredentials
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
</code></pre><p>Before running the application, make sure the database is updated with OpenIddict tables by running <code>Add-Migration</code> and <code>Update-Database</code>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="../styles/jquery.twbsPagination.js"></script>
|
||||
<script type="text/javascript" src="../styles/url.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/anchor-js/anchor.min.js"></script>
|
||||
<script type="text/javascript" src="../styles/docfx.js"></script>
|
||||
<script type="text/javascript" src="../styles/main.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
123
guides/index.html
Normal file
123
guides/index.html
Normal file
@@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE]><![endif]-->
|
||||
<html>
|
||||
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Introduction </title>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="title" content="Introduction ">
|
||||
<meta name="generator" content="docfx 2.56.7.0">
|
||||
|
||||
<link rel="shortcut icon" href="../images/favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/night-owl.min.css">
|
||||
<link rel="stylesheet" href="../styles/colors.css">
|
||||
<link rel="stylesheet" href="../styles/discord.css">
|
||||
<link rel="stylesheet" href="../styles/main.css">
|
||||
<meta property="docfx:navrel" content="../toc.html">
|
||||
<meta property="docfx:tocrel" content="toc.html">
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="top-navbar">
|
||||
|
||||
<a href="javascript:void(0);" class="burger-icon" onclick="toggleMenu()">
|
||||
<svg name="Hamburger" style="vertical-align: middle;" width="24" height="24" viewbox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M20 6H4V9H20V6ZM4 10.999H20V13.999H4V10.999ZM4 15.999H20V18.999H4V15.999Z"></path></svg>
|
||||
</a>
|
||||
|
||||
|
||||
<a class="brand" href="../index.html">
|
||||
<img src="../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
|
||||
<div id="blackout" class="blackout" onclick="toggleMenu()"></div>
|
||||
|
||||
<nav id="sidebar" role="navigation">
|
||||
|
||||
<div class="sidebar">
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a class="brand" href="../index.html">
|
||||
<img src="../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
<div id="navbar">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sidebar-item-separator"></div>
|
||||
|
||||
|
||||
<div id="sidetoggle">
|
||||
<div id="sidetoc"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<span>Generated by <strong>DocFX</strong></span>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main-panel">
|
||||
|
||||
<div role="main" class="hide-when-search">
|
||||
|
||||
|
||||
<div class="subnav navbar navbar-default">
|
||||
<div class="container hide-when-search" id="breadcrumb">
|
||||
<ul class="breadcrumb">
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<article class="content wrap" id="_content" data-uid="">
|
||||
<h1 id="introduction">Introduction</h1>
|
||||
|
||||
<h2 id="whats-openiddict">What's OpenIddict?</h2>
|
||||
<p>OpenIddict was born in late 2015 and was initially based on <strong><a href="https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server">AspNet.Security.OpenIdConnect.Server</a></strong>
|
||||
(codenamed ASOS), a low-level OpenID Connect server middleware forked from OWIN/Katana's <code>OAuthAuthorizationServerMiddleware</code>. In 2020, ASOS was merged into OpenIddict 3.0
|
||||
to form a unified stack under the OpenIddict umbrella, while still offering an easy-to-use approach for new users and a low-level experience for advanced users.</p>
|
||||
<h2 id="why-an-openid-connect-server">Why an OpenID Connect server?</h2>
|
||||
<p>Adding an OpenID Connect server to your application <strong>allows you to support token authentication</strong>.
|
||||
It also allows you to manage all your users using local password or an external identity provider (e.g. Facebook or Google) for all your
|
||||
applications in one central place, with the power to control who can access your API and the information that is exposed to each client.</p>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="../styles/jquery.twbsPagination.js"></script>
|
||||
<script type="text/javascript" src="../styles/url.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/anchor-js/anchor.min.js"></script>
|
||||
<script type="text/javascript" src="../styles/docfx.js"></script>
|
||||
<script type="text/javascript" src="../styles/main.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
363
guides/migration/20-to-30.html
Normal file
363
guides/migration/20-to-30.html
Normal file
@@ -0,0 +1,363 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE]><![endif]-->
|
||||
<html>
|
||||
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Migrate to OpenIddict 3.0 </title>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="title" content="Migrate to OpenIddict 3.0 ">
|
||||
<meta name="generator" content="docfx 2.56.7.0">
|
||||
|
||||
<link rel="shortcut icon" href="../../images/favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/night-owl.min.css">
|
||||
<link rel="stylesheet" href="../../styles/colors.css">
|
||||
<link rel="stylesheet" href="../../styles/discord.css">
|
||||
<link rel="stylesheet" href="../../styles/main.css">
|
||||
<meta property="docfx:navrel" content="../../toc.html">
|
||||
<meta property="docfx:tocrel" content="../toc.html">
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="top-navbar">
|
||||
|
||||
<a href="javascript:void(0);" class="burger-icon" onclick="toggleMenu()">
|
||||
<svg name="Hamburger" style="vertical-align: middle;" width="24" height="24" viewbox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M20 6H4V9H20V6ZM4 10.999H20V13.999H4V10.999ZM4 15.999H20V18.999H4V15.999Z"></path></svg>
|
||||
</a>
|
||||
|
||||
|
||||
<a class="brand" href="../../index.html">
|
||||
<img src="../../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
|
||||
<div id="blackout" class="blackout" onclick="toggleMenu()"></div>
|
||||
|
||||
<nav id="sidebar" role="navigation">
|
||||
|
||||
<div class="sidebar">
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a class="brand" href="../../index.html">
|
||||
<img src="../../images/logo.png" alt="OpenIddict" class="logomark">
|
||||
<span class="brand-title">OpenIddict</span>
|
||||
</a>
|
||||
<div id="navbar">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sidebar-item-separator"></div>
|
||||
|
||||
|
||||
<div id="sidetoggle">
|
||||
<div id="sidetoc"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<span>Generated by <strong>DocFX</strong></span>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main-panel">
|
||||
|
||||
<div role="main" class="hide-when-search">
|
||||
|
||||
|
||||
<div class="subnav navbar navbar-default">
|
||||
<div class="container hide-when-search" id="breadcrumb">
|
||||
<ul class="breadcrumb">
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<article class="content wrap" id="_content" data-uid="">
|
||||
<h1 id="migrate-to-openiddict-30">Migrate to OpenIddict 3.0</h1>
|
||||
|
||||
<h2 id="whats-new">What's new?</h2>
|
||||
<p>The announcement listing the changes introduced in this milestone can be found <a href="https://kevinchalet.com/2020/12/23/openiddict-3-0-general-availability/">here</a>.</p>
|
||||
<div class="IMPORTANT"><h5>Important</h5><p><strong>Migrating to OpenIddict 3.0 requires making changes to your database</strong>: existing properties have been reworked and new ones have been added to support the new features.</p>
|
||||
</div>
|
||||
<h2 id="update-your-packages-references">Update your packages references</h2>
|
||||
<p>For that, update your <code>.csproj</code> file to reference the <code>OpenIddict.AspNetCore</code> 3.x metapackage:</p>
|
||||
<pre><code class="lang-xml"><ItemGroup>
|
||||
<PackageReference Include="OpenIddict.AspNetCore" Version="3.1.1" />
|
||||
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.1.1" />
|
||||
</ItemGroup>
|
||||
</code></pre><h2 id="ensure-your-application-doesnt-reference-legacyunsupported-packages">Ensure your application doesn't reference legacy/unsupported packages</h2>
|
||||
<p>As part of the AspNet.Security.OpenIdConnect.Server/OpenIddict merge, the ASOS packages and 2 OpenIddict packages have been marked as legacy
|
||||
and are no longer supported. Make sure your application (or intermediate libraries) don't reference any of these packages:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Package name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>AspNet.Security.OpenIdConnect.Extensions</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AspNet.Security.OpenIdConnect.Primitives</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AspNet.Security.OpenIdConnect.Server</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Owin.Security.OpenIdConnect.Extensions</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Owin.Security.OpenIdConnect.Server</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AspNet.Security.OAuth.Introspection</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AspNet.Security.OAuth.Validation</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Owin.Security.OAuth.Introspection</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Owin.Security.OAuth.Validation</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddict.Models</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddict.Mvc</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="IMPORTANT"><h5>Important</h5><p>If your application references the <code>OpenIdConnectConstants</code> class, update it to use <code>OpenIddictConstants</code> instead.</p>
|
||||
</div>
|
||||
<h2 id="update-the-references-to-the-entity-framework-coreentity-framework-6mongodb-models">Update the references to the Entity Framework Core/Entity Framework 6/MongoDB models</h2>
|
||||
<p>If your application references the <code>OpenIddictApplication</code>, <code>OpenIddictAuthorization</code>, <code>OpenIddictScope</code> or <code>OpenIddictToken</code> models, update these reference to use
|
||||
their new names: <code>OpenIddict[provider name]Application</code>, <code>OpenIddict[provider name]Authorization</code>, <code>OpenIddict[provider name]Scope</code> and <code>OpenIddict[provider name]Token</code>
|
||||
(e.g when using MongoDB: <code>OpenIddictMongoDbApplication</code>, <code>OpenIddictMongoDbAuthorization</code>, <code>OpenIddictMongoDbScope</code> and <code>OpenIddictMongoDbToken</code>).</p>
|
||||
<h2 id="enable-aspnet-core-integration-in-the-server-and-validation-options">Enable ASP.NET Core integration in the server and validation options</h2>
|
||||
<p>With the base server and validation stacks being decoupled from ASP.NET Core, you now have to explicitly register the ASP.NET Core host in the server/validation options:</p>
|
||||
<pre><code class="lang-csharp">services.AddOpenIddict()
|
||||
.AddServer(options =>
|
||||
{
|
||||
options.UseAspNetCore();
|
||||
})
|
||||
.AddValidation(options =>
|
||||
{
|
||||
options.UseAspNetCore();
|
||||
});
|
||||
</code></pre><h2 id="enable-the-authorization-logout-and-token-endpoints-pass-through-mode">Enable the authorization, logout and token endpoints pass-through mode</h2>
|
||||
<p>Unless you're using OpenIddict's events model to handle authorization, logout and token requests, you'll need to enable
|
||||
the pass-through mode for these endpoints, so that requests can reach your authorization controller as in the previous versions:</p>
|
||||
<pre><code class="lang-csharp">services.AddOpenIddict()
|
||||
.AddServer(options =>
|
||||
{
|
||||
options.UseAspNetCore()
|
||||
.EnableAuthorizationEndpointPassthrough()
|
||||
.EnableLogoutEndpointPassthrough()
|
||||
.EnableTokenEndpointPassthrough();
|
||||
});
|
||||
</code></pre><h2 id="enable-aspnet-core-data-protection-support-to-ensure-existing-tokens-can-still-be-validated">Enable ASP.NET Core Data Protection support to ensure existing tokens can still be validated</h2>
|
||||
<p>For that, call <code>options.UseDataProtection()</code> in both the server and validation options:</p>
|
||||
<pre><code class="lang-csharp">services.AddOpenIddict()
|
||||
.AddServer(options =>
|
||||
{
|
||||
options.UseDataProtection();
|
||||
})
|
||||
.AddValidation(options =>
|
||||
{
|
||||
options.UseDataProtection();
|
||||
});
|
||||
</code></pre><h2 id="use-the-new-request-caching-apis-if-applicable">Use the new request caching APIs, if applicable</h2>
|
||||
<p>In 3.0, the <code>OpenIddictServerBuilder.EnableRequestCaching()</code> API - that enabled request caching for both authorization and logout request -
|
||||
was replaced by 2 separate methods. If your application depends on request caching, don't forget to enable it when migrating to 3.0:</p>
|
||||
<pre><code class="lang-csharp">services.AddOpenIddict()
|
||||
.AddServer(options =>
|
||||
{
|
||||
options.UseAspNetCore()
|
||||
.EnableAuthorizationRequestCaching()
|
||||
.EnableLogoutRequestCaching();
|
||||
});
|
||||
</code></pre><h2 id="replace-jsonnet-by-systemtextjson">Replace JSON.NET by <code>System.Text.Json</code></h2>
|
||||
<p>If you use JSON.NET to serialize or deserialize <code>OpenIdConnectMessage</code>, <code>OpenIdConnectRequest</code> or <code>OpenIdConnectResponse</code> instances,
|
||||
consider moving to <code>System.Text.Json</code> when migrating to OpenIddict 3.0, as 3.0 no longer includes a built-in JSON.NET <code>JsonConverter</code> for their
|
||||
equivalent in 3.0 (i.e <code>OpenIddictMessage</code>, <code>OpenIddictRequest</code> and <code>OpenIddictResponse</code>).</p>
|
||||
<p>In most cases, this should be as simple as replacing <code>JsonConvert.SerializeObject()</code>/<code>JsonConvert.DeserializeObject()</code>
|
||||
by their <code>System.Text.Json</code> equivalent: <code>JsonSerializer.Serialize()</code>/<code>JsonSerializer.Deserialize()</code>.</p>
|
||||
<h2 id="replace-calls-to-the-authenticationticket-extensions-by-their-new-claimsprincipal-equivalent">Replace calls to the <code>AuthenticationTicket</code> extensions by their new <code>ClaimsPrincipal</code> equivalent:</h2>
|
||||
<p>OpenIddict 3.0 no longer uses the <code>AuthenticationTicket</code> type provided by ASP.NET Core. Instead, everything is now stored in the <code>ClaimsPrincipal</code> instance.
|
||||
If you have calls like <code>ticket.SetScopes()</code> or <code>ticket.SetResources()</code>, use their new equivalents (e.g <code>principal.SetScopes()</code> or <code>principal.SetResources()</code>).</p>
|
||||
<h2 id="use-the-new-authentication-schemes">Use the new authentication schemes</h2>
|
||||
<p>In 3.0, the constants used as the ASP.NET Core authentication schemes have changed:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Old constant name</th>
|
||||
<th>New constant name (ASP.NET Core host)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>OpenIddictServerDefaults.AuthenticationScheme</td>
|
||||
<td>OpenIddictServerAspNetCoreDefaults.AuthenticationScheme</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddictValidationDefaults.AuthenticationScheme</td>
|
||||
<td>OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OAuthValidationDefaults.AuthenticationScheme</td>
|
||||
<td>OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="NOTE"><h5>Note</h5><p>In 3.0, the OpenIddict server ASP.NET Core handler supports authenticating userinfo requests. As such, if you use the pass-through mode
|
||||
to handle userinfo requests in your own userinfo MVC action, consider using <code>OpenIddictServerAspNetCoreDefaults.AuthenticationScheme</code>
|
||||
instead of <code>OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme</code> for your userinfo endpoint to avoid validating access tokens twice.</p>
|
||||
</div>
|
||||
<h2 id="update-your-application-to-work-with-the-new-scope-format">Update your application to work with the new <code>scope</code> format</h2>
|
||||
<p>In OpenIddict 3.0, the format of the <code>scope</code> claim used in JWT tokens has changed from a JSON array to a single space-separated claim
|
||||
to match <a href="https://datatracker.ietf.org/doc/html/rfc9068">the JWT access token specification</a>. To ensure your authorization policies
|
||||
still work after migrating, consider using the <code>principal.HasScope()</code> extension to determine whether a scope has been granted:</p>
|
||||
<pre><code class="lang-csharp">services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("MyPolicy", builder =>
|
||||
{
|
||||
builder.RequireAuthenticatedUser();
|
||||
builder.RequireAssertion(context => context.User.HasScope("api1"));
|
||||
});
|
||||
});
|
||||
</code></pre><p>Alternatively, you can use the check the presence of the private OpenIddict <code>oi_scp</code> claims that use the same format as in 2.x (i.e one claim per scope value):</p>
|
||||
<pre><code class="lang-csharp">services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("MyPolicy", builder =>
|
||||
{
|
||||
builder.RequireAuthenticatedUser();
|
||||
builder.RequireClaim(Claims.Private.Scope, "api1");
|
||||
});
|
||||
});
|
||||
</code></pre><div class="CAUTION"><h5>Caution</h5><p>These 2 options only work with the OpenIddict validation handler as the <code>oi_scp</code> claims are not populated by the JWT bearer handler developped by Microsoft.
|
||||
If you can't migrate to the OpenIddict validation handler, consider splitting the standard <code>scope</code> claim manually to determine whether it contains a specific value.</p>
|
||||
</div>
|
||||
<h2 id="add-and-apply-migrations-if-necessary">Add and apply migrations, if necessary</h2>
|
||||
<p>If your application uses Entity Framework Core or Entity Framework 6, add a migration to react to the schema changes listed below and apply it.</p>
|
||||
<h3 id="updated-properties">Updated properties</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Table</th>
|
||||
<th>Column name</th>
|
||||
<th>Observations</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>OpenIddictAuthorizations</td>
|
||||
<td>Subject</td>
|
||||
<td>The column is now nullable to support the device authorization flow.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddictTokens</td>
|
||||
<td>CreationDate</td>
|
||||
<td>For broader database support, this column is a now a <code>DateTime</code> instance.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddictTokens</td>
|
||||
<td>ExpirationDate</td>
|
||||
<td>For broader database support, this column is a now a <code>DateTime</code> instance.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddictTokens</td>
|
||||
<td>Subject</td>
|
||||
<td>The column is now nullable to support the device authorization flow.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="added-properties">Added properties</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Table</th>
|
||||
<th>Column name</th>
|
||||
<th>Type</th>
|
||||
<th>Nullable</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>OpenIddictAuthorizations</td>
|
||||
<td>CreationDate</td>
|
||||
<td>DateTime</td>
|
||||
<td>Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenIddictTokens</td>
|
||||
<td>RedemptionDate</td>
|
||||
<td>DateTime</td>
|
||||
<td>Yes</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 id="if-necessary-enable-hybrid-flow-support-in-the-server-options">If necessary, enable hybrid flow support in the server options</h2>
|
||||
<p>In 2.0, the hybrid flow was automatically enabled if both the authorization code and implicit flows were enabled. In 3.0, this is no longer true
|
||||
and the hybrid flow MUST be explicitly opted in. If you use the hybrid flow, make sure your application calls the <code>options.AllowHybridFlow()</code> method:</p>
|
||||
<pre><code class="lang-csharp">services.AddOpenIddict()
|
||||
.AddServer(options =>
|
||||
{
|
||||
options.AllowHybridFlow();
|
||||
});
|
||||
</code></pre><h2 id="update-your-applications-to-grant-them-the-appropriate-response-type-permissions">Update your applications to grant them the appropriate response type permissions</h2>
|
||||
<p>New response type permissions - enforced by default - <a href="/configuration/application-permissions.html#response-type-permissions">have been introduced in 3.0</a>.</p>
|
||||
<p>If you have many applications to migrate, you can use <a href="https://github.com/openiddict/openiddict-core/issues/1138#issuecomment-713681158">this script</a>
|
||||
to infer appropriate response type permissions using the already granted grant types.</p>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="../../styles/jquery.twbsPagination.js"></script>
|
||||
<script type="text/javascript" src="../../styles/url.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/anchor-js/anchor.min.js"></script>
|
||||
<script type="text/javascript" src="../../styles/docfx.js"></script>
|
||||
<script type="text/javascript" src="../../styles/main.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
52
guides/toc.html
Normal file
52
guides/toc.html
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
<div id="sidetoggle">
|
||||
<div>
|
||||
<div class="sidetoc">
|
||||
<div class="toc" id="toc">
|
||||
|
||||
<ul class="nav level1">
|
||||
<li>
|
||||
<a href="index.html" class="sidebar-item" name="" title="Introduction">Introduction</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<a href="getting-started.html" class="sidebar-item" name="" title="Getting started">Getting started</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<a href="choosing-the-right-flow.html" class="sidebar-item" name="" title="Choosing the right flow">Choosing the right flow</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<span class="expand-stub"></span>
|
||||
<a class="sidebar-item" name="" title="Migration guides">Migration guides</a>
|
||||
|
||||
|
||||
<ul class="nav level2">
|
||||
<li>
|
||||
<a href="migration/20-to-30.html" class="sidebar-item" name="" title="Migration from 2.0 to 3.0">Migration from 2.0 to 3.0</a>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<span class="expand-stub"></span>
|
||||
<a class="sidebar-item" name="" title="External resources">External resources</a>
|
||||
|
||||
|
||||
<ul class="nav level2">
|
||||
<li>
|
||||
<a href="https://tools.ietf.org/html/rfc6749" class="sidebar-item" name="" title="OAuth 2.0 specification">OAuth 2.0 specification</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://openid.net/specs/openid-connect-core-1_0.html" class="sidebar-item" name="" title="OpenID Connect specification">OpenID Connect specification</a>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user