Configured projects to use api

pull/221/head
Halil İbrahim Kalkan 7 years ago
parent a1a29176df
commit 6e306e4c13

@ -0,0 +1,28 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace MicroserviceDemo.TenancyService.Controllers
{
[Route("[controller]")]
[Authorize]
public class IdentityController : AbpController
{
[HttpGet]
public IActionResult Get()
{
return new JsonResult(new
{
currentUserId = CurrentUser.Id,
currentUserEmail = CurrentUser.Email,
currentUserRoles = CurrentUser.Roles,
currentUserUserName = CurrentUser.UserName,
claims = from c in User.Claims select new { c.Type, c.Value }
});
}
}
}

@ -1,111 +0,0 @@
2018-02-28 10:18:23.368 +03:00 [Information] Loaded modules:
2018-02-28 10:18:23.444 +03:00 [Information] - Volo.Abp.Castle.AbpCastleCoreModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.Autofac.AbpAutofacModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.Data.AbpDataModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.Settings.AbpSettingsModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyAbstractionsModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyDomainSharedModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.Guids.AbpGuidsModule
2018-02-28 10:18:23.445 +03:00 [Information] - Volo.Abp.ObjectMapping.AbpObjectMappingModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Threading.AbpThreadingModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.EventBus.AbpEventBusModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Validation.AbpValidationModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Security.AbpSecurityModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Authorization.AbpAuthorizationModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Http.AbpHttpAbstractionsModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.AbpDddModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.AutoMapper.AbpAutoMapperModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Ui.AbpUiModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyDomainModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.VirtualFileSystem.AbpVirtualFileSystemModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Localization.AbpLocalizationModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Session.AbpSessionModule
2018-02-28 10:18:23.446 +03:00 [Information] - Volo.Abp.Timing.AbpTimingModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.Json.AbpJsonModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.ApiVersioning.AbpApiVersioningAbstractionsModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.Serialization.AbpSerializationModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.Caching.AbpCachingModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.AbpCommonModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.MultiTenancy.EntityFrameworkCore.AbpMultiTenancyEntityFrameworkCoreModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyApplicationContractsModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyApplicationModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.Http.AbpHttpModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.AspNetCore.AbpAspNetCoreModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.AspNetCore.Mvc.AbpAspNetCoreMvcModule
2018-02-28 10:18:23.447 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyHttpApiModule
2018-02-28 10:18:23.447 +03:00 [Information] - MicroserviceDemo.TenancyService.MicroservicesDemoTenancyServiceModule
2018-02-28 10:18:24.855 +03:00 [Information] Initialized all modules.
2018-02-28 10:18:25.686 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/
2018-02-28 10:18:26.185 +03:00 [Information] Executing action method "MicroserviceDemo.TenancyService.Controllers.HomeController.Index (MicroserviceDemo.TenancyService)" with arguments (null) - ModelState is Valid
2018-02-28 10:18:26.211 +03:00 [Information] Executing RedirectResult, redirecting to "/swagger".
2018-02-28 10:18:26.222 +03:00 [Information] Executed action "MicroserviceDemo.TenancyService.Controllers.HomeController.Index (MicroserviceDemo.TenancyService)" in 132.0196ms
2018-02-28 10:18:26.236 +03:00 [Information] Request finished in 606.1366ms 302
2018-02-28 10:18:26.286 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/swagger/
2018-02-28 10:18:26.322 +03:00 [Information] Request finished in 36.5045ms 200 text/html
2018-02-28 10:18:27.379 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/swagger/v1/swagger.json
2018-02-28 10:18:27.916 +03:00 [Information] Request finished in 537.0078ms 200 application/json
2018-02-28 10:26:40.794 +03:00 [Information] Loaded modules:
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.Castle.AbpCastleCoreModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.Autofac.AbpAutofacModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.Data.AbpDataModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.Settings.AbpSettingsModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyAbstractionsModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyDomainSharedModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.Guids.AbpGuidsModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.ObjectMapping.AbpObjectMappingModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.Threading.AbpThreadingModule
2018-02-28 10:26:40.839 +03:00 [Information] - Volo.Abp.EventBus.AbpEventBusModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Validation.AbpValidationModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Security.AbpSecurityModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Authorization.AbpAuthorizationModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Http.AbpHttpAbstractionsModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.AbpDddModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.AutoMapper.AbpAutoMapperModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Ui.AbpUiModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyDomainModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.VirtualFileSystem.AbpVirtualFileSystemModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Localization.AbpLocalizationModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Session.AbpSessionModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Timing.AbpTimingModule
2018-02-28 10:26:40.840 +03:00 [Information] - Volo.Abp.Json.AbpJsonModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.ApiVersioning.AbpApiVersioningAbstractionsModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.Serialization.AbpSerializationModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.Caching.AbpCachingModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.AbpCommonModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.MultiTenancy.EntityFrameworkCore.AbpMultiTenancyEntityFrameworkCoreModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyApplicationContractsModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.Http.AbpHttpModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.AspNetCore.AbpAspNetCoreModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.AspNetCore.Mvc.AbpAspNetCoreMvcModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyHttpApiModule
2018-02-28 10:26:40.841 +03:00 [Information] - Volo.Abp.MultiTenancy.AbpMultiTenancyApplicationModule
2018-02-28 10:26:40.841 +03:00 [Information] - MicroserviceDemo.TenancyService.MicroservicesDemoTenancyServiceModule
2018-02-28 10:26:41.517 +03:00 [Information] Initialized all modules.
2018-02-28 10:26:41.796 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/
2018-02-28 10:26:41.981 +03:00 [Information] Executing action method "MicroserviceDemo.TenancyService.Controllers.HomeController.Index (MicroserviceDemo.TenancyService)" with arguments (null) - ModelState is Valid
2018-02-28 10:26:41.991 +03:00 [Information] Executing RedirectResult, redirecting to "/swagger".
2018-02-28 10:26:41.997 +03:00 [Information] Executed action "MicroserviceDemo.TenancyService.Controllers.HomeController.Index (MicroserviceDemo.TenancyService)" in 48.397ms
2018-02-28 10:26:42.004 +03:00 [Information] Request finished in 223.508ms 302
2018-02-28 10:26:42.028 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/swagger/
2018-02-28 10:26:42.050 +03:00 [Information] Request finished in 22.5978ms 200 text/html
2018-02-28 10:26:42.363 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/swagger/v1/swagger.json
2018-02-28 10:26:42.655 +03:00 [Information] Request finished in 291.932ms 200 application/json
2018-02-28 10:26:52.866 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/api/multi-tenancy/tenant?SkipCount=0&MaxResultCount=11
2018-02-28 10:26:53.026 +03:00 [Information] Executing action method "Volo.Abp.MultiTenancy.TenantController.GetListAsync (Volo.Abp.MultiTenancy.HttpApi)" with arguments (["Volo.Abp.MultiTenancy.GetTenantsInput"]) - ModelState is Valid
2018-02-28 10:26:53.093 +03:00 [Information] Authorization was successful for user: null.
2018-02-28 10:26:54.213 +03:00 [Information] Executing ObjectResult, writing value "Microsoft.AspNetCore.Mvc.ControllerContext".
2018-02-28 10:26:54.221 +03:00 [Information] Executed action "Volo.Abp.MultiTenancy.TenantController.GetListAsync (Volo.Abp.MultiTenancy.HttpApi)" in 1324.7568ms
2018-02-28 10:26:54.222 +03:00 [Information] Request finished in 1355.0906ms 200 application/json; charset=utf-8
2018-02-28 10:27:23.527 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/api/abp/api-definition
2018-02-28 10:27:23.537 +03:00 [Information] Executing action method "Volo.Abp.AspNetCore.Mvc.ApiExploring.AbpApiDefinitionController.Get (Volo.Abp.AspNetCore.Mvc)" with arguments (null) - ModelState is Valid
2018-02-28 10:27:23.561 +03:00 [Information] Executing ObjectResult, writing value "Microsoft.AspNetCore.Mvc.ControllerContext".
2018-02-28 10:27:23.580 +03:00 [Information] Executed action "Volo.Abp.AspNetCore.Mvc.ApiExploring.AbpApiDefinitionController.Get (Volo.Abp.AspNetCore.Mvc)" in 51.1608ms
2018-02-28 10:27:23.581 +03:00 [Information] Request finished in 54.061ms 200 application/json; charset=utf-8
2018-02-28 10:27:23.661 +03:00 [Information] Request starting HTTP/1.1 GET http://localhost:63877/api/multi-tenancy/tenant?SkipCount=0&MaxResultCount=10&api-version=1.0
2018-02-28 10:27:23.665 +03:00 [Information] Executing action method "Volo.Abp.MultiTenancy.TenantController.GetListAsync (Volo.Abp.MultiTenancy.HttpApi)" with arguments (["Volo.Abp.MultiTenancy.GetTenantsInput"]) - ModelState is Valid
2018-02-28 10:27:23.666 +03:00 [Information] Authorization was successful for user: null.
2018-02-28 10:27:23.688 +03:00 [Information] Executing ObjectResult, writing value "Microsoft.AspNetCore.Mvc.ControllerContext".
2018-02-28 10:27:23.690 +03:00 [Information] Executed action "Volo.Abp.MultiTenancy.TenantController.GetListAsync (Volo.Abp.MultiTenancy.HttpApi)" in 27.1663ms
2018-02-28 10:27:23.690 +03:00 [Information] Request finished in 29.127ms 200 application/json; charset=utf-8

@ -16,6 +16,7 @@
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="2.1.0" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
@ -23,6 +24,7 @@
<ProjectReference Include="..\..\Volo.Abp.MultiTenancy.Application\Volo.Abp.MultiTenancy.Application.csproj" />
<ProjectReference Include="..\..\Volo.Abp.MultiTenancy.EntityFrameworkCore\Volo.Abp.MultiTenancy.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\Volo.Abp.MultiTenancy.HttpApi\Volo.Abp.MultiTenancy.HttpApi.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Permissions.EntityFrameworkCore\Volo.Abp.Permissions.EntityFrameworkCore.csproj" />
</ItemGroup>
</Project>

@ -6,12 +6,16 @@ using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Autofac;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.EntityFrameworkCore;
using Volo.Abp.Permissions.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
using Volo.Abp.Threading;
namespace MicroserviceDemo.TenancyService
{
@ -19,6 +23,7 @@ namespace MicroserviceDemo.TenancyService
[DependsOn(typeof(AbpMultiTenancyEntityFrameworkCoreModule))]
[DependsOn(typeof(AbpMultiTenancyHttpApiModule))]
[DependsOn(typeof(AbpMultiTenancyApplicationModule))]
[DependsOn(typeof(AbpPermissionsEntityFrameworkCoreModule))]
public class MicroservicesDemoTenancyServiceModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
@ -50,9 +55,21 @@ namespace MicroserviceDemo.TenancyService
options.DocInclusionPredicate((docName, description) => true);
});
services.AddAuthentication();
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:54307";
options.RequireHttpsMetadata = false;
options.ApiName = "multi-tenancy-api";
services.AddAlwaysAllowPermissionChecker();
//This should be automatically done :(
options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId;
options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role;
options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email;
});
//services.AddAlwaysAllowPermissionChecker();
services.AddAssemblyOf<MicroservicesDemoTenancyServiceModule>();
}
@ -61,6 +78,9 @@ namespace MicroserviceDemo.TenancyService
{
var app = context.GetApplicationBuilder();
var store = context.ServiceProvider.GetRequiredService<IPermissionStore>();
var xx = AsyncHelper.RunSync(() => store.IsGrantedAsync("AbpTenantManagement.Tenants", "Role", "admin"));
app.UseStaticFiles();
app.UseSwagger();

@ -1,5 +1,6 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=MicroservicesDemo.Tenancy;Trusted_Connection=True;MultipleActiveResultSets=true"
"Default": "Server=localhost;Database=MicroservicesDemo.Tenancy;Trusted_Connection=True;MultipleActiveResultSets=true",
"AbpPermissions": "Server=localhost;Database=MicroservicesDemo.Permissions;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

@ -1,6 +1,10 @@
using System.Threading.Tasks;
using System.Net.Http;
using System.Threading.Tasks;
using IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Volo.Abp.AspNetCore.Mvc;
namespace MicroserviceDemo.Web.Controllers
@ -12,5 +16,30 @@ namespace MicroserviceDemo.Web.Controllers
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
await HttpContext.SignOutAsync("oidc");
}
public async Task<IActionResult> CallApiUsingUserAccessToken()
{
var accessToken = await HttpContext.GetTokenAsync("access_token");
var client = new HttpClient();
client.SetBearerToken(accessToken);
var content = await client.GetStringAsync("http://localhost:63877/identity");
ViewBag.Json = JObject.Parse(content).ToString();
return View("json");
}
public async Task<IActionResult> CallApiUsingClientCredentials()
{
var tokenClient = new TokenClient("http://localhost:54307/connect/token", "client", "secret");
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("multi-tenancy-api");
var client = new HttpClient();
client.SetBearerToken(tokenResponse.AccessToken);
var content = await client.GetStringAsync("http://localhost:63877/identity");
ViewBag.Json = JObject.Parse(content).ToString();
return View("json");
}
}
}

@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="2.1.0" />
<PackageReference Include="IdentityModel" Version="3.0.0" />
</ItemGroup>
<ItemGroup>

@ -0,0 +1,3 @@
<h2>API response</h2>
<pre>@ViewBag.Json</pre>
Loading…
Cancel
Save