mirror of
https://gitee.com/dcren/openiddict-documentation.git
synced 2025-04-24 18:04:57 +08:00
332 lines
14 KiB
HTML
332 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<!--[if IE]><![endif]-->
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
<title>Application permissions </title>
|
|
<meta name="viewport" content="width=device-width">
|
|
<meta name="title" content="Application permissions ">
|
|
<meta name="generator" content="docfx 2.56.6.0">
|
|
|
|
<link rel="shortcut icon" href="../images/favicon.ico">
|
|
<link rel="stylesheet" href="../styles/docfx.vendor.css">
|
|
<link rel="stylesheet" href="../styles/docfx.css">
|
|
<link rel="stylesheet" href="../styles/main.css">
|
|
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
|
|
<meta property="docfx:navrel" content="../toc.html">
|
|
<meta property="docfx:tocrel" content="toc.html">
|
|
|
|
|
|
|
|
</head> <body data-spy="scroll" data-target="#affix" data-offset="120">
|
|
<div id="wrapper">
|
|
<header>
|
|
|
|
<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
|
|
<span class="sr-only">Toggle navigation</span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
|
|
<a class="navbar-brand" href="../index.html">
|
|
<img id="logo" class="svg" src="../images/logo.svg" alt="">
|
|
</a>
|
|
</div>
|
|
<div class="collapse navbar-collapse" id="navbar">
|
|
<form class="navbar-form navbar-right" role="search" id="search">
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="subnav navbar navbar-default">
|
|
<div class="container hide-when-search" id="breadcrumb">
|
|
<ul class="breadcrumb">
|
|
<li></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<div role="main" class="container body-content hide-when-search">
|
|
|
|
<div class="sidenav hide-when-search">
|
|
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
|
|
<div class="sidetoggle collapse" id="sidetoggle">
|
|
<div id="sidetoc"></div>
|
|
</div>
|
|
</div>
|
|
<div class="article row grid-right">
|
|
<div class="col-md-10">
|
|
<article class="content wrap" id="_content" data-uid="">
|
|
<h1 id="application-permissions">Application permissions</h1>
|
|
|
|
<p>Starting with RC2, OpenIddict includes a built-in feature codenamed "application permissions" that
|
|
<strong>allows controlling and limiting the OAuth2/OpenID Connect features a client application is able to use</strong>.</p>
|
|
<p>3 categories of permissions are currently supported:</p>
|
|
<ul>
|
|
<li>Endpoint permissions</li>
|
|
<li>Grant type/flow permissions</li>
|
|
<li>Scope permissions.</li>
|
|
</ul>
|
|
<div class="WARNING"><h5>Warning</h5><p>Note: <strong>prior to OpenIddict RC3, application permissions were mostly optional</strong> and OpenIddict had a fallback mechanism
|
|
called "implicit permissions" it used to determine whether an application could perform the requested action.</p>
|
|
<p>If no permission was explicitly attached to the application, it was considered fully trusted and was granted all the permissions.
|
|
Similarly, if you granted the "token endpoint" permission to an application but NO "grant type" permission,
|
|
it was assumed the client application was allowed to use the password or client credentials grants.</p>
|
|
<p>Retrospectively, this logic was too complex and was removed in RC3: <strong>application permissions MUST now be explicitly granted</strong>.</p>
|
|
</div>
|
|
<h2 id="endpoint-permissions">Endpoint permissions</h2>
|
|
<h3 id="definition">Definition</h3>
|
|
<p>Endpoint permissions limit the endpoints a client application can use.</p>
|
|
<h3 id="supported-permissions">Supported permissions</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Endpoint</th>
|
|
<th style="text-align:center">Constant</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center">Authorization endpoint</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Endpoints.Authorization</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Introspection endpoint</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Endpoints.Introspection</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Logout/end session endpoint</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Endpoints.Logout</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Revocation endpoint</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Endpoints.Revocation</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Token endpoint</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Endpoints.Token</code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h3 id="example">Example</h3>
|
|
<p>In the following example, the <code>mvc</code> application is allowed to use the authorization, logout and
|
|
token endpoints but will get an error when trying to send an introspection or revocation request:</p>
|
|
<pre><code class="lang-csharp">if (await manager.FindByClientIdAsync("mvc") == null)
|
|
{
|
|
await manager.CreateAsync(new OpenIddictApplicationDescriptor
|
|
{
|
|
ClientId = "mvc",
|
|
ClientSecret = "901564A5-E7FE-42CB-B10D-61EF6A8F3654",
|
|
DisplayName = "MVC client application",
|
|
PostLogoutRedirectUris = { new Uri("http://localhost:53507/signout-callback-oidc") },
|
|
RedirectUris = { new Uri("http://localhost:53507/signin-oidc") },
|
|
Permissions =
|
|
{
|
|
OpenIddictConstants.Permissions.Endpoints.Authorization,
|
|
OpenIddictConstants.Permissions.Endpoints.Logout,
|
|
OpenIddictConstants.Permissions.Endpoints.Token
|
|
}
|
|
});
|
|
}
|
|
</code></pre><h3 id="disabling-endpoint-permissions">Disabling endpoint permissions</h3>
|
|
<p>If you don't want to use endpoint permissions, call <code>options.IgnoreEndpointPermissions()</code> to ignore them:</p>
|
|
<pre><code class="lang-csharp">services.AddOpenIddict()
|
|
.AddServer(options =>
|
|
{
|
|
options.IgnoreEndpointPermissions();
|
|
});
|
|
</code></pre><h2 id="grant-type-permissions">Grant type permissions</h2>
|
|
<h3 id="definition-1">Definition</h3>
|
|
<p>Grant type permissions limit the flows a client application is allowed to use.</p>
|
|
<h3 id="supported-permissions-1">Supported permissions</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Grant type</th>
|
|
<th style="text-align:center">Constant</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center">Authorization code flow</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Client credentials flow</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.GrantTypes.ClientCredentials</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Implicit flow</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.GrantTypes.Implicit</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Password flow</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.GrantTypes.Password</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">Refresh token flow</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.GrantTypes.RefreshToken</code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>To add a custom flow permission, you can use the following pattern:</p>
|
|
<pre><code class="lang-csharp">OpenIddictConstants.Permissions.Prefixes.GrantType + "custom_flow_name"
|
|
</code></pre><h3 id="example-1">Example</h3>
|
|
<p>In the following example, the <code>postman</code> application can only use the authorization code flow
|
|
while <code>console</code> is restricted to the <code>password</code> and <code>refresh_token</code> flows:</p>
|
|
<pre><code class="lang-csharp">if (await manager.FindByClientIdAsync("postman") == null)
|
|
{
|
|
await manager.CreateAsync(new OpenIddictApplicationDescriptor
|
|
{
|
|
ClientId = "postman",
|
|
DisplayName = "Postman",
|
|
RedirectUris = { new Uri("https://www.getpostman.com/oauth2/callback") },
|
|
Permissions =
|
|
{
|
|
OpenIddictConstants.Permissions.Endpoints.Authorization,
|
|
OpenIddictConstants.Permissions.Endpoints.Token,
|
|
|
|
OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode
|
|
}
|
|
});
|
|
}
|
|
|
|
if (await manager.FindByClientIdAsync("console") == null)
|
|
{
|
|
await manager.CreateAsync(new OpenIddictApplicationDescriptor
|
|
{
|
|
ClientId = "console",
|
|
DisplayName = "Console",
|
|
Permissions =
|
|
{
|
|
OpenIddictConstants.Permissions.Endpoints.Token,
|
|
|
|
OpenIddictConstants.Permissions.GrantTypes.Password,
|
|
OpenIddictConstants.Permissions.GrantTypes.RefreshToken
|
|
}
|
|
});
|
|
}
|
|
</code></pre><h3 id="disabling-grant-type-permissions">Disabling grant type permissions</h3>
|
|
<p>If you don't want to use grant type permissions, call <code>options.IgnoreGrantTypePermissions()</code> to ignore them:</p>
|
|
<pre><code class="lang-csharp">services.AddOpenIddict()
|
|
.AddServer(options =>
|
|
{
|
|
options.IgnoreGrantTypePermissions();
|
|
});
|
|
</code></pre><h2 id="scope-permissions">Scope permissions</h2>
|
|
<h3 id="definition-2">Definition</h3>
|
|
<p>Scope permissions limit the scopes (standard or custom) a client application is allowed to use.</p>
|
|
<blockquote><p>The <code>openid</code> and <code>offline_access</code> scopes are special-cased by OpenIddict and don't require explicit permissions.</p>
|
|
</blockquote>
|
|
<h3 id="supported-permissions-2">Supported permissions</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Scope</th>
|
|
<th style="text-align:center">Constant</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center">address</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Scopes.Address</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">email</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Scopes.Email</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">phone</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Scopes.Phone</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">profile</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Scopes.Profile</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center">roles</td>
|
|
<td style="text-align:center"><code>OpenIddictConstants.Permissions.Scopes.Roles</code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>To add a custom scope permission, you can use the following pattern:</p>
|
|
<pre><code class="lang-csharp">OpenIddictConstants.Permissions.Prefixes.Scope + "custom_scope_name"
|
|
</code></pre><h3 id="example-2">Example</h3>
|
|
<p>In the following sample, the <code>angular</code> client is allowed to request the <code>address</code>,
|
|
<code>profile</code> and <code>marketing_api</code> scopes: any other scope will result in an error being returned.</p>
|
|
<pre><code class="lang-csharp">if (await manager.FindByClientIdAsync("angular") == null)
|
|
{
|
|
await manager.CreateAsync(new OpenIddictApplicationDescriptor
|
|
{
|
|
ClientId = "angular",
|
|
DisplayName = "Angular",
|
|
RedirectUris = { new Uri("https://localhost:34422/callback") },
|
|
Permissions =
|
|
{
|
|
OpenIddictConstants.Permissions.Endpoints.Authorization,
|
|
OpenIddictConstants.Permissions.GrantTypes.Implicit,
|
|
|
|
OpenIddictConstants.Permissions.Scopes.Address,
|
|
OpenIddictConstants.Permissions.Scopes.Profile,
|
|
OpenIddictConstants.Permissions.Prefixes.Scope + "marketing_api"
|
|
}
|
|
});
|
|
}
|
|
</code></pre><h3 id="disabling-scope-permissions">Disabling scope permissions</h3>
|
|
<p>If you don't want to use scope permissions, call <code>options.IgnoreScopePermissions()</code> to ignore them:</p>
|
|
<pre><code class="lang-csharp">services.AddOpenIddict()
|
|
.AddServer(options =>
|
|
{
|
|
options.IgnoreScopePermissions();
|
|
});
|
|
</code></pre></article>
|
|
</div>
|
|
|
|
<div class="hidden-sm col-md-2" role="complementary">
|
|
<div class="sideaffix">
|
|
<div class="contribution">
|
|
<ul class="nav">
|
|
<li>
|
|
<a href="https://github.com/openiddict/openiddict-documentation/blob/dev/configuration/application-permissions.md/#L1" class="contribution-link">Improve this Doc</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
|
|
<h5>In This Article</h5>
|
|
<div></div>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer>
|
|
<div class="grad-bottom"></div>
|
|
<div class="footer">
|
|
<div class="container">
|
|
<span class="pull-right">
|
|
<a href="#top">Back to top</a>
|
|
</span>
|
|
|
|
<span>Generated by <strong>DocFX</strong></span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</div>
|
|
|
|
<script type="text/javascript" src="../styles/docfx.vendor.js"></script>
|
|
<script type="text/javascript" src="../styles/docfx.js"></script>
|
|
<script type="text/javascript" src="../styles/main.js"></script>
|
|
</body>
|
|
</html>
|