@ -4,6 +4,7 @@ using System.Threading.Tasks;
using IdentityModel.Client ;
using Acme.BookStore.BookManagement.Books ;
using Acme.BookStore.BookManagement.Samples ;
using Microsoft.Extensions.Configuration ;
using Volo.Abp.Application.Dtos ;
using Volo.Abp.Configuration ;
using Volo.Abp.DependencyInjection ;
@ -15,18 +16,18 @@ namespace Acme.BookStore.BookManagement
{
private readonly ISampleAppService _ sampleAppService ;
private readonly IIdentityModelAuthenticationService _ authenticationService ;
private readonly IConfigurationAccessor _ configurationAccessor ;
private readonly IConfiguration _ configuration ;
private readonly IBookAppService _ bookAppService ;
public ClientDemoService (
ISampleAppService sampleAppService ,
IIdentityModelAuthenticationService authenticationService ,
IConfigurationAccessor configurationAccessor ,
IConfiguration configuration ,
IBookAppService bookAppService )
{
_ sampleAppService = sampleAppService ;
_ authenticationService = authenticationService ;
_ configurationAccessor = configurationAccessor ;
_ configuration = configuration ;
_ bookAppService = bookAppService ;
}
@ -71,13 +72,13 @@ namespace Acme.BookStore.BookManagement
var accessToken = await _ authenticationService . GetAccessTokenAsync (
new IdentityClientConfiguration (
_ configurationAccessor . Configuration [ "IdentityClients:Default:Authority" ] ,
_ configurationAccessor . Configuration [ "IdentityClients:Default:Scope" ] ,
_ configurationAccessor . Configuration [ "IdentityClients:Default:ClientId" ] ,
_ configurationAccessor . Configuration [ "IdentityClients:Default:ClientSecret" ] ,
_ configurationAccessor . Configuration [ "IdentityClients:Default:GrantType" ] ,
_ configurationAccessor . Configuration [ "IdentityClients:Default:UserName" ] ,
_ configurationAccessor . Configuration [ "IdentityClients:Default:UserPassword" ]
_ 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" ]
)
) ;
@ -87,7 +88,7 @@ namespace Acme.BookStore.BookManagement
{
httpClient . SetBearerToken ( accessToken ) ;
var url = _ configurationAccessor . Configuration [ "RemoteServices:BookManagement:BaseUrl" ] +
var url = _ configuration [ "RemoteServices:BookManagement:BaseUrl" ] +
"api/BookManagement/sample/authorized" ;
var responseMessage = await httpClient . GetAsync ( url ) ;
@ -116,7 +117,7 @@ namespace Acme.BookStore.BookManagement
// discover endpoints from metadata
var client = new HttpClient ( ) ;
var disco = await client . GetDiscoveryDocumentAsync ( _ configurationAccessor . Configuration [ "IdentityClients:Default:Authority" ] ) ;
var disco = await client . GetDiscoveryDocumentAsync ( _ configuration [ "IdentityClients:Default:Authority" ] ) ;
if ( disco . IsError )
{
Console . WriteLine ( disco . Error ) ;
@ -127,11 +128,11 @@ namespace Acme.BookStore.BookManagement
var tokenResponse = await client . RequestPasswordTokenAsync ( new PasswordTokenRequest
{
Address = disco . TokenEndpoint ,
ClientId = _ configurationAccessor . Configuration [ "IdentityClients:Default:ClientId" ] ,
ClientSecret = _ configurationAccessor . Configuration [ "IdentityClients:Default:ClientSecret" ] ,
UserName = _ configurationAccessor . Configuration [ "IdentityClients:Default:UserName" ] ,
Password = _ configurationAccessor . Configuration [ "IdentityClients:Default:UserPassword" ] ,
Scope = _ configurationAccessor . Configuration [ "IdentityClients:Default:Scope" ]
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 )
@ -148,7 +149,7 @@ namespace Acme.BookStore.BookManagement
{
httpClient . SetBearerToken ( tokenResponse . AccessToken ) ;
var url = _ configurationAccessor . Configuration [ "RemoteServices:BookManagement:BaseUrl" ] +
var url = _ configuration [ "RemoteServices:BookManagement:BaseUrl" ] +
"api/BookManagement/sample/authorized" ;
var responseMessage = await httpClient . GetAsync ( url ) ;