Browse Source

Resolve `Conflicting method/path` problem.

pull/12624/head
maliming 4 years ago
parent
commit
b8b8431124
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 39
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpFormValueRequiredAttribute.cs
  2. 4
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs
  3. 14
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AbpOpenIdDictControllerBase.cs
  4. 23
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs
  5. 28
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/LogoutController.cs
  6. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.cs
  7. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/UserInfoController.cs
  8. 6
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Views/Authorize/Authorize.cshtml
  9. 4
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Views/Logout/Logout.cshtml
  10. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/en.json
  11. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/tr.json
  12. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/zh-Hans.json
  13. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/zh-Hant.json
  14. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs

39
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpFormValueRequiredAttribute.cs

@ -1,39 +0,0 @@
using System;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Routing;
namespace Volo.Abp.OpenIddict;
public class AbpFormValueRequiredAttribute : ActionMethodSelectorAttribute
{
private readonly string _name;
public AbpFormValueRequiredAttribute(string name)
{
_name = name;
}
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
if (string.Equals(routeContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) ||
string.Equals(routeContext.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) ||
string.Equals(routeContext.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) ||
string.Equals(routeContext.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (string.IsNullOrEmpty(routeContext.HttpContext.Request.ContentType))
{
return false;
}
if (!routeContext.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
{
return false;
}
return !string.IsNullOrEmpty(routeContext.HttpContext.Request.Form[_name]);
}
}

4
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs

@ -53,13 +53,13 @@ public class AbpOpenIddictAspNetCoreModule : AbpModule
.AddServer(builder => .AddServer(builder =>
{ {
builder builder
.SetAuthorizationEndpointUris("/connect/authorize") .SetAuthorizationEndpointUris("/connect/authorize", "/connect/authorize/callback")
// /.well-known/oauth-authorization-server // /.well-known/oauth-authorization-server
// /.well-known/openid-configuration // /.well-known/openid-configuration
//.SetConfigurationEndpointUris() //.SetConfigurationEndpointUris()
// /.well-known/jwks // /.well-known/jwks
//.SetCryptographyEndpointUris() //.SetCryptographyEndpointUris()
.SetDeviceEndpointUris("/connect/device") .SetDeviceEndpointUris("/device")
.SetIntrospectionEndpointUris("/connect/introspect") .SetIntrospectionEndpointUris("/connect/introspect")
.SetLogoutEndpointUris("/connect/logout") .SetLogoutEndpointUris("/connect/logout")
.SetRevocationEndpointUris("/connect/revocat") .SetRevocationEndpointUris("/connect/revocat")

14
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AbpOpenIdDictControllerBase.cs

@ -59,4 +59,18 @@ public abstract class AbpOpenIdDictControllerBase : AbpController
{ {
await OpenIddictClaimDestinationsManager.SetAsync(principal); await OpenIddictClaimDestinationsManager.SetAsync(principal);
} }
protected virtual async Task<bool> HasFormValueAsync(string name)
{
if (Request.HasFormContentType)
{
var form = await Request.ReadFormAsync();
if (!string.IsNullOrEmpty(form[name]))
{
return true;
}
}
return false;
}
} }

23
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs

@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using OpenIddict.Abstractions; using OpenIddict.Abstractions;
using OpenIddict.Server.AspNetCore; using OpenIddict.Server.AspNetCore;
@ -16,6 +15,7 @@ using Volo.Abp.OpenIddict.ViewModels.Authorization;
namespace Volo.Abp.OpenIddict.Controllers; namespace Volo.Abp.OpenIddict.Controllers;
[Route("connect/authorize")] [Route("connect/authorize")]
[ApiExplorerSettings(IgnoreApi = true)]
public class AuthorizeController : AbpOpenIdDictControllerBase public class AuthorizeController : AbpOpenIdDictControllerBase
{ {
[HttpGet, HttpPost] [HttpGet, HttpPost]
@ -159,9 +159,17 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
} }
[HttpPost] [HttpPost]
[Authorize, AbpFormValueRequired("submit.Accept")] [Authorize]
public virtual async Task<IActionResult> HandleAcceptConsentAsync() [Route("callback")]
public virtual async Task<IActionResult> HandleCallbackAsync()
{ {
if (await HasFormValueAsync("deny"))
{
// Notify OpenIddict that the authorization grant has been denied by the resource owner
// to redirect the user agent to the client application using the appropriate response_mode.
return Forbid(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
}
var request = await GetOpenIddictServerRequestAsync(HttpContext); var request = await GetOpenIddictServerRequestAsync(HttpContext);
// Retrieve the profile of the logged in user. // Retrieve the profile of the logged in user.
@ -224,13 +232,4 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
// Returning a SignInResult will ask OpenIddict to issue the appropriate access/identity tokens. // Returning a SignInResult will ask OpenIddict to issue the appropriate access/identity tokens.
return SignIn(principal, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); return SignIn(principal, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
} }
[Authorize, AbpFormValueRequired("submit.Deny")]
[HttpPost]
public virtual Task<IActionResult> HandleDenyConsentAsync()
{
// Notify OpenIddict that the authorization grant has been denied by the resource owner
// to redirect the user agent to the client application using the appropriate response_mode.
return Task.FromResult<IActionResult>(Forbid(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme));
}
} }

28
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/LogoutController.cs

@ -1,12 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using OpenIddict.Server.AspNetCore; using OpenIddict.Server.AspNetCore;
namespace Volo.Abp.OpenIddict.Controllers; namespace Volo.Abp.OpenIddict.Controllers;
[Route("connect/logout")] [Route("connect/logout")]
[ApiExplorerSettings(IgnoreApi = true)]
public class LogoutController : AbpOpenIdDictControllerBase public class LogoutController : AbpOpenIdDictControllerBase
{ {
[HttpGet] [HttpGet]
@ -16,13 +16,15 @@ public class LogoutController : AbpOpenIdDictControllerBase
} }
[HttpPost] [HttpPost]
[AbpFormValueRequired("submit.Accept")] public virtual async Task<IActionResult> PostAsync()
public virtual async Task<IActionResult> HandleAcceptAsync()
{ {
// Ask ASP.NET Core Identity to delete the local and external cookies created if (await HasFormValueAsync("accept"))
// when the user agent is redirected from the external identity provider {
// after a successful authentication flow (e.g Google or Facebook). // Ask ASP.NET Core Identity to delete the local and external cookies created
await SignInManager.SignOutAsync(); // when the user agent is redirected from the external identity provider
// after a successful authentication flow (e.g Google or Facebook).
await SignInManager.SignOutAsync();
}
// Returning a SignOutResult will ask OpenIddict to redirect the user agent // Returning a SignOutResult will ask OpenIddict to redirect the user agent
// to the post_logout_redirect_uri specified by the client application or to // to the post_logout_redirect_uri specified by the client application or to
@ -31,16 +33,4 @@ public class LogoutController : AbpOpenIdDictControllerBase
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties {RedirectUri = "/"}); properties: new AuthenticationProperties {RedirectUri = "/"});
} }
[HttpPost]
[AbpFormValueRequired("submit.Deny")]
public virtual Task<IActionResult> HandleDenyConsentAsync()
{
// Returning a SignOutResult will ask OpenIddict to redirect the user agent
// to the post_logout_redirect_uri specified by the client application or to
// the RedirectUri specified in the authentication properties if none was set.
return Task.FromResult<IActionResult>(SignOut(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties {RedirectUri = "/"}));
}
} }

1
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.cs

@ -9,6 +9,7 @@ using Volo.Abp.OpenIddict.ExtensionGrantTypes;
namespace Volo.Abp.OpenIddict.Controllers; namespace Volo.Abp.OpenIddict.Controllers;
[Route("connect/token")] [Route("connect/token")]
[ApiExplorerSettings(IgnoreApi = true)]
public partial class TokenController : AbpOpenIdDictControllerBase public partial class TokenController : AbpOpenIdDictControllerBase
{ {
[HttpGet, HttpPost, Produces("application/json")] [HttpGet, HttpPost, Produces("application/json")]

1
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/UserInfoController.cs

@ -12,6 +12,7 @@ namespace Volo.Abp.OpenIddict.Controllers;
[Route("connect/userinfo")] [Route("connect/userinfo")]
[Authorize(AuthenticationSchemes = OpenIddictServerAspNetCoreDefaults.AuthenticationScheme)] [Authorize(AuthenticationSchemes = OpenIddictServerAspNetCoreDefaults.AuthenticationScheme)]
[ApiExplorerSettings(IgnoreApi = true)]
public class UserInfoController : AbpOpenIdDictControllerBase public class UserInfoController : AbpOpenIdDictControllerBase
{ {
[HttpGet] [HttpGet]

6
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Views/Authorize/Authorize.cshtml

@ -9,7 +9,7 @@
<p class="lead text-left"><strong>@string.Format(L["DoYouWantToGrantAccessToYourData"].Value, Model.ApplicationName)</strong></p> <p class="lead text-left"><strong>@string.Format(L["DoYouWantToGrantAccessToYourData"].Value, Model.ApplicationName)</strong></p>
<p class="fw-light">@L["ScopesRequested"]: @Model.Scope</p> <p class="fw-light">@L["ScopesRequested"]: @Model.Scope</p>
<form method="post" action="~/connect/authorize" > <form method="post" action="~/connect/authorize/callback" >
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
@* Flow the request parameters so they can be received by the Accept/Reject actions: *@ @* Flow the request parameters so they can be received by the Accept/Reject actions: *@
@foreach (var parameter in Context.Request.HasFormContentType ? (IEnumerable<KeyValuePair<string, StringValues>>) Context.Request.Form : Context.Request.Query) @foreach (var parameter in Context.Request.HasFormContentType ? (IEnumerable<KeyValuePair<string, StringValues>>) Context.Request.Form : Context.Request.Query)
@ -17,7 +17,7 @@
<input type="hidden" name="@parameter.Key" value="@parameter.Value"/> <input type="hidden" name="@parameter.Key" value="@parameter.Value"/>
} }
<input class="btn btn-primary" name="submit.Accept" type="submit" value="@L["Yes"]"/> <input class="btn btn-primary" name="accept" type="submit" value="@L["Accept"]"/>
<input class="btn btn-danger ms-1" name="submit.Deny" type="submit" value="@L["No"]"/> <input class="btn btn-danger ms-1" name="deny" type="submit" value="@L["Deny"]"/>
</form> </form>
</div> </div>

4
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Views/Logout/Logout.cshtml

@ -16,7 +16,7 @@
<input type="hidden" name="@parameter.Key" value="@parameter.Value"/> <input type="hidden" name="@parameter.Key" value="@parameter.Value"/>
} }
<input class="btn btn-primary" name="submit.Accept" type="submit" value="@L["Yes"]"/> <input class="btn btn-primary" name="accept" type="submit" value="@L["Accept"]"/>
<input class="btn btn-danger ms-1" name="submit.Deny" type="submit" value="@L["No"]"/> <input class="btn btn-danger ms-1" name="deny" type="submit" value="@L["Deny"]"/>
</form> </form>
</div> </div>

2
modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/en.json

@ -9,6 +9,8 @@
"Authorization": "Authorization", "Authorization": "Authorization",
"DoYouWantToGrantAccessToYourData": "Do you want to grant {0} access to your data?", "DoYouWantToGrantAccessToYourData": "Do you want to grant {0} access to your data?",
"ScopesRequested": "Scopes requested", "ScopesRequested": "Scopes requested",
"Accept": "Accept",
"Deny": "Deny",
"LogOut": "Log out", "LogOut": "Log out",
"AreYouSureYouWantToSignOut": "Are you sure you want to sign out?" "AreYouSureYouWantToSignOut": "Are you sure you want to sign out?"
} }

2
modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/tr.json

@ -9,6 +9,8 @@
"Authorization": "Yetki", "Authorization": "Yetki",
"DoYouWantToGrantAccessToYourData": "Do you want to grant {0} access to your data?", "DoYouWantToGrantAccessToYourData": "Do you want to grant {0} access to your data?",
"ScopesRequested": "İstenen kapsamlar", "ScopesRequested": "İstenen kapsamlar",
"Accept": "Kabul etmek",
"Deny": "Reddetmek",
"LogOut": "Çıkış Yap", "LogOut": "Çıkış Yap",
"AreYouSureYouWantToSignOut": "Çıkış yapmak istediğinden emin misin?" "AreYouSureYouWantToSignOut": "Çıkış yapmak istediğinden emin misin?"
} }

2
modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/zh-Hans.json

@ -9,6 +9,8 @@
"Authorization": "授权", "Authorization": "授权",
"DoYouWantToGrantAccessToYourData": "是否要授予 {0} 访问你的数据的权限?", "DoYouWantToGrantAccessToYourData": "是否要授予 {0} 访问你的数据的权限?",
"ScopesRequested": "要求的Scope", "ScopesRequested": "要求的Scope",
"Accept": "同意",
"Deny": "拒绝",
"LogOut": "注销", "LogOut": "注销",
"AreYouSureYouWantToSignOut": "你确定要退出吗?" "AreYouSureYouWantToSignOut": "你确定要退出吗?"
} }

2
modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/zh-Hant.json

@ -10,6 +10,8 @@
"Authorization": "授權", "Authorization": "授權",
"DoYouWantToGrantAccessToYourData": "是否要授予 {0} 訪問你的數據的權限?", "DoYouWantToGrantAccessToYourData": "是否要授予 {0} 訪問你的數據的權限?",
"ScopesRequested": "要求的Scope", "ScopesRequested": "要求的Scope",
"Accept": "接受",
"Deny": "拒絕",
"LogOut": "註銷", "LogOut": "註銷",
"AreYouSureYouWantToSignOut": "你確定要退出嗎?" "AreYouSureYouWantToSignOut": "你確定要退出嗎?"
} }

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs

@ -168,7 +168,6 @@ public class MyProjectNameHttpApiHostModule : AbpModule
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" }); options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true); options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName); options.CustomSchemaIds(type => type.FullName);
options.ResolveConflictingActions(x => x.First());
}); });
} }

Loading…
Cancel
Save