mirror of https://github.com/abpframework/abp.git
40 changed files with 43 additions and 638 deletions
@ -1,19 +0,0 @@ |
|||||
using Volo.CmsKit.Localization; |
|
||||
using Volo.Abp.Authorization.Permissions; |
|
||||
using Volo.Abp.Localization; |
|
||||
|
|
||||
namespace Volo.CmsKit.Permissions |
|
||||
{ |
|
||||
public class CmsKitPermissionDefinitionProvider : PermissionDefinitionProvider |
|
||||
{ |
|
||||
public override void Define(IPermissionDefinitionContext context) |
|
||||
{ |
|
||||
var myGroup = context.AddGroup(CmsKitPermissions.GroupName, L("Permission:CmsKit")); |
|
||||
} |
|
||||
|
|
||||
private static LocalizableString L(string name) |
|
||||
{ |
|
||||
return LocalizableString.Create<CmsKitResource>(name); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
using Volo.Abp.Reflection; |
|
||||
|
|
||||
namespace Volo.CmsKit.Permissions |
|
||||
{ |
|
||||
public class CmsKitPermissions |
|
||||
{ |
|
||||
public const string GroupName = "CmsKit"; |
|
||||
|
|
||||
public static string[] GetAll() |
|
||||
{ |
|
||||
return ReflectionHelper.GetPublicConstantsRecursively(typeof(CmsKitPermissions)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
namespace Volo.CmsKit.Reactions |
|
||||
{ |
|
||||
public class CreateReactionDto |
|
||||
{ |
|
||||
public string EntityName { get; set; } |
|
||||
|
|
||||
public string EntityId { get; set; } |
|
||||
|
|
||||
public string ReactionType { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace Volo.CmsKit.Reactions |
|
||||
{ |
|
||||
public class GetReactionResultDto |
|
||||
{ |
|
||||
public List<ReactionCountDto> AllReactions { get; set; } |
|
||||
|
|
||||
//TODO: Reactions of the current user (if available)
|
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.Application.Services; |
|
||||
|
|
||||
namespace Volo.CmsKit.Reactions |
|
||||
{ |
|
||||
public interface IReactionAppService : IApplicationService |
|
||||
{ |
|
||||
public Task<GetReactionResultDto> CreateAsync(CreateReactionDto input); |
|
||||
|
|
||||
public Task<GetReactionResultDto> GetAsync(string entityName, string entityId); |
|
||||
} |
|
||||
} |
|
||||
@ -1,9 +0,0 @@ |
|||||
namespace Volo.CmsKit.Reactions |
|
||||
{ |
|
||||
public class ReactionCountDto |
|
||||
{ |
|
||||
public string ReactionType { get; set; } |
|
||||
|
|
||||
public int Count { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.Application.Services; |
|
||||
|
|
||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
public interface ISampleAppService : IApplicationService |
|
||||
{ |
|
||||
Task<SampleDto> GetAsync(); |
|
||||
|
|
||||
Task<SampleDto> GetAuthorizedAsync(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,7 +0,0 @@ |
|||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
public class SampleDto |
|
||||
{ |
|
||||
public int Value { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
using Volo.CmsKit.Localization; |
|
||||
using Volo.Abp.Application.Services; |
|
||||
|
|
||||
namespace Volo.CmsKit |
|
||||
{ |
|
||||
public abstract class CmsKitAppService : ApplicationService |
|
||||
{ |
|
||||
protected CmsKitAppService() |
|
||||
{ |
|
||||
LocalizationResource = typeof(CmsKitResource); |
|
||||
ObjectMapperContext = typeof(CmsKitApplicationModule); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
using AutoMapper; |
|
||||
|
|
||||
namespace Volo.CmsKit |
|
||||
{ |
|
||||
public class CmsKitApplicationAutoMapperProfile : Profile |
|
||||
{ |
|
||||
public CmsKitApplicationAutoMapperProfile() |
|
||||
{ |
|
||||
/* You can configure your AutoMapper mapping configuration here. |
|
||||
* Alternatively, you can split your mapping configurations |
|
||||
* into multiple profile classes for a better organization. */ |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,28 +1,14 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using Volo.Abp.Modularity; |
||||
using Volo.Abp.AutoMapper; |
|
||||
using Volo.Abp.Modularity; |
|
||||
using Volo.Abp.Application; |
|
||||
using Volo.CmsKit.Admin; |
|
||||
|
|
||||
namespace Volo.CmsKit |
namespace Volo.CmsKit |
||||
{ |
{ |
||||
[DependsOn( |
[DependsOn( |
||||
typeof(CmsKitDomainModule), |
|
||||
typeof(CmsKitApplicationContractsModule), |
|
||||
typeof(CmsKitPublicApplicationModule), |
typeof(CmsKitPublicApplicationModule), |
||||
typeof(CmsKitAdminApplicationModule), |
typeof(CmsKitAdminApplicationModule), |
||||
typeof(AbpDddApplicationModule), |
typeof(CmsKitApplicationContractsModule) |
||||
typeof(AbpAutoMapperModule) |
|
||||
)] |
)] |
||||
public class CmsKitApplicationModule : AbpModule |
public class CmsKitApplicationModule : AbpModule |
||||
{ |
{ |
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
context.Services.AddAutoMapperObjectMapper<CmsKitApplicationModule>(); |
|
||||
Configure<AbpAutoMapperOptions>(options => |
|
||||
{ |
|
||||
options.AddMaps<CmsKitApplicationModule>(validate: true); |
|
||||
}); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,17 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace Volo.CmsKit.Reactions |
|
||||
{ |
|
||||
public class ReactionAppService : CmsKitAppService, IReactionAppService |
|
||||
{ |
|
||||
public Task<GetReactionResultDto> CreateAsync(CreateReactionDto input) |
|
||||
{ |
|
||||
throw new System.NotImplementedException(); |
|
||||
} |
|
||||
|
|
||||
public Task<GetReactionResultDto> GetAsync(string entityName, string entityId) |
|
||||
{ |
|
||||
throw new System.NotImplementedException(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Authorization; |
|
||||
|
|
||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
public class SampleAppService : CmsKitAppService, ISampleAppService |
|
||||
{ |
|
||||
public Task<SampleDto> GetAsync() |
|
||||
{ |
|
||||
return Task.FromResult( |
|
||||
new SampleDto |
|
||||
{ |
|
||||
Value = 42 |
|
||||
} |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
[Authorize] |
|
||||
public Task<SampleDto> GetAuthorizedAsync() |
|
||||
{ |
|
||||
return Task.FromResult( |
|
||||
new SampleDto |
|
||||
{ |
|
||||
Value = 42 |
|
||||
} |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,22 +1,14 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using Volo.Abp.Modularity; |
||||
using Volo.Abp.Http.Client; |
|
||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace Volo.CmsKit |
namespace Volo.CmsKit |
||||
{ |
{ |
||||
[DependsOn( |
[DependsOn( |
||||
typeof(CmsKitApplicationContractsModule), |
typeof(CmsKitAdminHttpApiClientModule), |
||||
typeof(AbpHttpClientModule))] |
typeof(CmsKitPublicHttpApiClientModule), |
||||
|
typeof(CmsKitApplicationContractsModule) |
||||
|
)] |
||||
public class CmsKitHttpApiClientModule : AbpModule |
public class CmsKitHttpApiClientModule : AbpModule |
||||
{ |
{ |
||||
public const string RemoteServiceName = "CmsKit"; |
|
||||
|
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
context.Services.AddHttpClientProxies( |
|
||||
typeof(CmsKitApplicationContractsModule).Assembly, |
|
||||
RemoteServiceName |
|
||||
); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,13 +0,0 @@ |
|||||
using Volo.CmsKit.Localization; |
|
||||
using Volo.Abp.AspNetCore.Mvc; |
|
||||
|
|
||||
namespace Volo.CmsKit |
|
||||
{ |
|
||||
public abstract class CmsKitController : AbpController |
|
||||
{ |
|
||||
protected CmsKitController() |
|
||||
{ |
|
||||
LocalizationResource = typeof(CmsKitResource); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,33 +1,14 @@ |
|||||
using Localization.Resources.AbpUi; |
using Volo.Abp.Modularity; |
||||
using Volo.CmsKit.Localization; |
|
||||
using Volo.Abp.AspNetCore.Mvc; |
|
||||
using Volo.Abp.Localization; |
|
||||
using Volo.Abp.Modularity; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.CmsKit |
namespace Volo.CmsKit |
||||
{ |
{ |
||||
[DependsOn( |
[DependsOn( |
||||
typeof(CmsKitApplicationContractsModule), |
typeof(CmsKitAdminApplicationModule), |
||||
typeof(AbpAspNetCoreMvcModule))] |
typeof(CmsKitPublicApplicationModule), |
||||
|
typeof(CmsKitApplicationContractsModule) |
||||
|
)] |
||||
public class CmsKitHttpApiModule : AbpModule |
public class CmsKitHttpApiModule : AbpModule |
||||
{ |
{ |
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
PreConfigure<IMvcBuilder>(mvcBuilder => |
|
||||
{ |
|
||||
mvcBuilder.AddApplicationPartIfNotExists(typeof(CmsKitHttpApiModule).Assembly); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
Configure<AbpLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.Resources |
|
||||
.Get<CmsKitResource>() |
|
||||
.AddBaseTypes(typeof(AbpUiResource)); |
|
||||
}); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,33 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Authorization; |
|
||||
using Microsoft.AspNetCore.Mvc; |
|
||||
using Volo.Abp; |
|
||||
|
|
||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
[RemoteService] |
|
||||
[Route("api/CmsKit/sample")] |
|
||||
public class SampleController : CmsKitController, ISampleAppService |
|
||||
{ |
|
||||
private readonly ISampleAppService _sampleAppService; |
|
||||
|
|
||||
public SampleController(ISampleAppService sampleAppService) |
|
||||
{ |
|
||||
_sampleAppService = sampleAppService; |
|
||||
} |
|
||||
|
|
||||
[HttpGet] |
|
||||
public async Task<SampleDto> GetAsync() |
|
||||
{ |
|
||||
return await _sampleAppService.GetAsync(); |
|
||||
} |
|
||||
|
|
||||
[HttpGet] |
|
||||
[Route("authorized")] |
|
||||
[Authorize] |
|
||||
public async Task<SampleDto> GetAuthorizedAsync() |
|
||||
{ |
|
||||
return await _sampleAppService.GetAsync(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
using AutoMapper; |
|
||||
|
|
||||
namespace Volo.CmsKit.Web |
|
||||
{ |
|
||||
public class CmsKitWebAutoMapperProfile : Profile |
|
||||
{ |
|
||||
public CmsKitWebAutoMapperProfile() |
|
||||
{ |
|
||||
/* You can configure your AutoMapper mapping configuration here. |
|
||||
* Alternatively, you can split your mapping configurations |
|
||||
* into multiple profile classes for a better organization. */ |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,63 +1,14 @@ |
|||||
using Microsoft.AspNetCore.Mvc.RazorPages; |
using Volo.Abp.Modularity; |
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.CmsKit.Localization; |
|
||||
using Volo.CmsKit.Web.Menus; |
|
||||
using Volo.Abp.AspNetCore.Mvc.Localization; |
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
|
||||
using Volo.Abp.AutoMapper; |
|
||||
using Volo.Abp.Modularity; |
|
||||
using Volo.Abp.UI.Navigation; |
|
||||
using Volo.Abp.VirtualFileSystem; |
|
||||
using Volo.CmsKit.Admin.Web; |
using Volo.CmsKit.Admin.Web; |
||||
using Volo.CmsKit.Permissions; |
|
||||
|
|
||||
namespace Volo.CmsKit.Web |
namespace Volo.CmsKit.Web |
||||
{ |
{ |
||||
[DependsOn( |
[DependsOn( |
||||
typeof(CmsKitHttpApiModule), |
|
||||
typeof(AbpAspNetCoreMvcUiThemeSharedModule), |
|
||||
typeof(AbpAutoMapperModule), |
|
||||
typeof(CmsKitPublicWebModule), |
typeof(CmsKitPublicWebModule), |
||||
typeof(CmsKitAdminWebModule) |
typeof(CmsKitAdminWebModule), |
||||
|
typeof(CmsKitHttpApiModule) |
||||
)] |
)] |
||||
public class CmsKitWebModule : AbpModule |
public class CmsKitWebModule : AbpModule |
||||
{ |
{ |
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.AddAssemblyResource(typeof(CmsKitResource), typeof(CmsKitWebModule).Assembly); |
|
||||
}); |
|
||||
|
|
||||
PreConfigure<IMvcBuilder>(mvcBuilder => |
|
||||
{ |
|
||||
mvcBuilder.AddApplicationPartIfNotExists(typeof(CmsKitWebModule).Assembly); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
Configure<AbpNavigationOptions>(options => |
|
||||
{ |
|
||||
options.MenuContributors.Add(new CmsKitMenuContributor()); |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpVirtualFileSystemOptions>(options => |
|
||||
{ |
|
||||
options.FileSets.AddEmbedded<CmsKitWebModule>(); |
|
||||
}); |
|
||||
|
|
||||
context.Services.AddAutoMapperObjectMapper<CmsKitWebModule>(); |
|
||||
|
|
||||
Configure<AbpAutoMapperOptions>(options => |
|
||||
{ |
|
||||
options.AddMaps<CmsKitWebModule>(validate: true); |
|
||||
}); |
|
||||
|
|
||||
Configure<RazorPagesOptions>(options => |
|
||||
{ |
|
||||
//Configure authorization.
|
|
||||
}); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,23 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.UI.Navigation; |
|
||||
|
|
||||
namespace Volo.CmsKit.Web.Menus |
|
||||
{ |
|
||||
public class CmsKitMenuContributor : IMenuContributor |
|
||||
{ |
|
||||
public async Task ConfigureMenuAsync(MenuConfigurationContext context) |
|
||||
{ |
|
||||
if (context.Menu.Name == StandardMenus.Main) |
|
||||
{ |
|
||||
await ConfigureMainMenu(context); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private Task ConfigureMainMenu(MenuConfigurationContext context) |
|
||||
{ |
|
||||
//Add main menu items.
|
|
||||
|
|
||||
return Task.CompletedTask; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
namespace Volo.CmsKit.Web.Menus |
|
||||
{ |
|
||||
public class CmsKitMenus |
|
||||
{ |
|
||||
private const string Prefix = "CmsKit"; |
|
||||
|
|
||||
//Add your menu items here...
|
|
||||
//public const string Home = Prefix + ".MyNewMenuItem";
|
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,9 +0,0 @@ |
|||||
@page |
|
||||
@using Microsoft.Extensions.Localization |
|
||||
@using Volo.CmsKit.Localization |
|
||||
@model Volo.CmsKit.Web.Pages.CmsKit.IndexModel |
|
||||
@inject IStringLocalizer<CmsKitResource> L |
|
||||
@{ |
|
||||
} |
|
||||
<h1>CmsKit</h1> |
|
||||
<p>@L["SamplePageMessage"]</p> |
|
||||
@ -1,9 +0,0 @@ |
|||||
namespace Volo.CmsKit.Web.Pages.CmsKit |
|
||||
{ |
|
||||
public class IndexModel : CmsKitPageModel |
|
||||
{ |
|
||||
public void OnGet() |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,7 +0,0 @@ |
|||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
|
||||
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI |
|
||||
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap |
|
||||
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|
||||
@addTagHelper *, Volo.CmsKit.Common.Web |
|
||||
@addTagHelper *, Volo.CmsKit.Public.Web |
|
||||
@addTagHelper *, Volo.CmsKit.Admin.Web |
|
||||
@ -1,16 +0,0 @@ |
|||||
using Volo.CmsKit.Localization; |
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; |
|
||||
|
|
||||
namespace Volo.CmsKit.Web.Pages |
|
||||
{ |
|
||||
/* Inherit your PageModel classes from this class. |
|
||||
*/ |
|
||||
public abstract class CmsKitPageModel : AbpPageModel |
|
||||
{ |
|
||||
protected CmsKitPageModel() |
|
||||
{ |
|
||||
LocalizationResourceType = typeof(CmsKitResource); |
|
||||
ObjectMapperContext = typeof(CmsKitWebModule); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Shouldly; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
public class SampleAppService_Tests : CmsKitApplicationTestBase |
|
||||
{ |
|
||||
private readonly ISampleAppService _sampleAppService; |
|
||||
|
|
||||
public SampleAppService_Tests() |
|
||||
{ |
|
||||
_sampleAppService = GetRequiredService<ISampleAppService>(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task GetAsync() |
|
||||
{ |
|
||||
var result = await _sampleAppService.GetAsync(); |
|
||||
result.Value.ShouldBe(42); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task GetAuthorizedAsync() |
|
||||
{ |
|
||||
var result = await _sampleAppService.GetAuthorizedAsync(); |
|
||||
result.Value.ShouldBe(42); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,156 +1,20 @@ |
|||||
using System; |
using System; |
||||
using System.Net.Http; |
|
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using IdentityModel.Client; |
|
||||
using Microsoft.Extensions.Configuration; |
|
||||
using Volo.CmsKit.Samples; |
|
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
using Volo.Abp.IdentityModel; |
|
||||
|
|
||||
namespace Volo.CmsKit |
namespace Volo.CmsKit |
||||
{ |
{ |
||||
public class ClientDemoService : ITransientDependency |
public class ClientDemoService : ITransientDependency |
||||
{ |
{ |
||||
private readonly ISampleAppService _sampleAppService; |
|
||||
private readonly IIdentityModelAuthenticationService _authenticationService; |
|
||||
private readonly IConfiguration _configuration; |
|
||||
|
|
||||
public ClientDemoService( |
|
||||
ISampleAppService sampleAppService, |
|
||||
IIdentityModelAuthenticationService authenticationService, |
|
||||
IConfiguration configuration) |
|
||||
{ |
|
||||
_sampleAppService = sampleAppService; |
|
||||
_authenticationService = authenticationService; |
|
||||
_configuration = configuration; |
|
||||
} |
|
||||
|
|
||||
public async Task RunAsync() |
public async Task RunAsync() |
||||
{ |
{ |
||||
await TestWithDynamicProxiesAsync(); |
await TestWithDynamicProxiesAsync(); |
||||
await TestWithHttpClientAndIdentityModelAuthenticationServiceAsync(); |
|
||||
await TestAllManuallyAsync(); |
|
||||
} |
} |
||||
|
|
||||
/* Shows how to perform an HTTP request to the API using ABP's dynamic c# proxy |
|
||||
* feature. It is just simple as calling a local service method. |
|
||||
* Authorization and HTTP request details are handled by the ABP framework. |
|
||||
*/ |
|
||||
private async Task TestWithDynamicProxiesAsync() |
private async Task TestWithDynamicProxiesAsync() |
||||
{ |
{ |
||||
Console.WriteLine(); |
Console.WriteLine(); |
||||
Console.WriteLine($"***** {nameof(TestWithDynamicProxiesAsync)} *****"); |
Console.WriteLine($"***** {nameof(TestWithDynamicProxiesAsync)} *****"); |
||||
|
|
||||
var result = await _sampleAppService.GetAsync(); |
|
||||
Console.WriteLine("Result: " + result.Value); |
|
||||
|
|
||||
result = await _sampleAppService.GetAuthorizedAsync(); |
|
||||
Console.WriteLine("Result (authorized): " + result.Value); |
|
||||
} |
|
||||
|
|
||||
/* Shows how to use HttpClient to perform a request to the HTTP API. |
|
||||
* It uses ABP's IIdentityModelAuthenticationService to simplify obtaining access tokens. |
|
||||
*/ |
|
||||
private async Task TestWithHttpClientAndIdentityModelAuthenticationServiceAsync() |
|
||||
{ |
|
||||
Console.WriteLine(); |
|
||||
Console.WriteLine($"***** {nameof(TestWithHttpClientAndIdentityModelAuthenticationServiceAsync)} *****"); |
|
||||
|
|
||||
//Get access token using ABP's IIdentityModelAuthenticationService
|
|
||||
|
|
||||
var accessToken = await _authenticationService.GetAccessTokenAsync( |
|
||||
new IdentityClientConfiguration( |
|
||||
_configuration["IdentityClients:Default:Authority"], |
|
||||
_configuration["IdentityClients:Default:Scope"], |
|
||||
_configuration["IdentityClients:Default:ClientId"], |
|
||||
_configuration["IdentityClients:Default:ClientSecret"], |
|
||||
_configuration["IdentityClients:Default:GrantType"], |
|
||||
_configuration["IdentityClients:Default:UserName"], |
|
||||
_configuration["IdentityClients:Default:UserPassword"] |
|
||||
) |
|
||||
); |
|
||||
|
|
||||
//Perform the actual HTTP request
|
|
||||
|
|
||||
using (var httpClient = new HttpClient()) |
|
||||
{ |
|
||||
httpClient.SetBearerToken(accessToken); |
|
||||
|
|
||||
var url = _configuration["RemoteServices:CmsKit:BaseUrl"] + |
|
||||
"api/CmsKit/sample/authorized"; |
|
||||
|
|
||||
var responseMessage = await httpClient.GetAsync(url); |
|
||||
if (responseMessage.IsSuccessStatusCode) |
|
||||
{ |
|
||||
var responseString = await responseMessage.Content.ReadAsStringAsync(); |
|
||||
Console.WriteLine("Result: " + responseString); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
throw new Exception("Remote server returns error code: " + responseMessage.StatusCode); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/* Shows how to use HttpClient to perform a request to the HTTP API. |
|
||||
* It obtains access token using IdentityServer's API. See its documentation: |
|
||||
* https://identityserver4.readthedocs.io/en/latest/quickstarts/2_resource_owner_passwords.html
|
|
||||
*/ |
|
||||
private async Task TestAllManuallyAsync() |
|
||||
{ |
|
||||
Console.WriteLine(); |
|
||||
Console.WriteLine($"***** {nameof(TestAllManuallyAsync)} *****"); |
|
||||
|
|
||||
//Obtain access token from the IDS4 server
|
|
||||
|
|
||||
// discover endpoints from metadata
|
|
||||
var client = new HttpClient(); |
|
||||
var disco = await client.GetDiscoveryDocumentAsync(_configuration["IdentityClients:Default:Authority"]); |
|
||||
if (disco.IsError) |
|
||||
{ |
|
||||
Console.WriteLine(disco.Error); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
// request token
|
|
||||
var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest |
|
||||
{ |
|
||||
Address = disco.TokenEndpoint, |
|
||||
ClientId = _configuration["IdentityClients:Default:ClientId"], |
|
||||
ClientSecret = _configuration["IdentityClients:Default:ClientSecret"], |
|
||||
UserName = _configuration["IdentityClients:Default:UserName"], |
|
||||
Password = _configuration["IdentityClients:Default:UserPassword"], |
|
||||
Scope = _configuration["IdentityClients:Default:Scope"] |
|
||||
}); |
|
||||
|
|
||||
if (tokenResponse.IsError) |
|
||||
{ |
|
||||
Console.WriteLine(tokenResponse.Error); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
Console.WriteLine(tokenResponse.Json); |
|
||||
|
|
||||
//Perform the actual HTTP request
|
|
||||
|
|
||||
using (var httpClient = new HttpClient()) |
|
||||
{ |
|
||||
httpClient.SetBearerToken(tokenResponse.AccessToken); |
|
||||
|
|
||||
var url = _configuration["RemoteServices:CmsKit:BaseUrl"] + |
|
||||
"api/CmsKit/sample/authorized"; |
|
||||
|
|
||||
var responseMessage = await httpClient.GetAsync(url); |
|
||||
if (responseMessage.IsSuccessStatusCode) |
|
||||
{ |
|
||||
var responseString = await responseMessage.Content.ReadAsStringAsync(); |
|
||||
Console.WriteLine("Result: " + responseString); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
throw new Exception("Remote server returns error code: " + responseMessage.StatusCode); |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue