public async Task RunAsync() { while (true) { using var activity = new Activity(nameof(RunAsync)).Start(); try { Console.WriteLine("トークンを取得し、APIを呼びだします。"); Console.ReadKey(); var response = await _tokenClient.RequestTokenAsync( new TokenSettings { AuthorityBaseUri = Constants.Authority.BaseUri }, Constants.ConsoleApp.ClientId, Constants.ConsoleApp.ClientSecret, new[] { Constants.Bff.ResourceName }); response.DumpConsole(); var data = await _bffClient.GetServiceUsersAsync(response.AccessToken); Console.WriteLine(JsonConvert.SerializeObject(data)); } catch (Exception e) { Console.WriteLine(e); } finally { activity.Stop(); } } }
public async Task <ServiceUser> GetServiceUsers() { var token = await _tokenClient.RequestTokenAsync(new TokenSettings { AuthorityBaseUri = Constants.Authority.BaseUri }, Constants.Bff.ClientId, Constants.Bff.ClientSecret, new[] { Constants.Backend1.ResourceName, Constants.Backend2.ResourceName, }); var contract = await _backend1Client.GetContractAsync("1", token.AccessToken); var apiUser = await _backend2Client.GetApiUserAsync("1", token.AccessToken); return(new ServiceUser { Jwt = (from c in User.Claims select new KeyValuePair <string, string>(c.Type, c.Value)).ToList(), Contract = contract, ApiUser = apiUser, }); }
public async Task <IActionResult> Secret() { var token = await _tokenClient.RequestTokenAsync(new TokenSettings { AuthorityBaseUri = Constants.Authority.BaseUri }, Constants.WebApp.ClientId, Constants.WebApp.ClientSecret, new[] { Constants.Bff.ResourceName }); var result = await _bffClient.GetServiceUsersAsync(token.AccessToken); var json = JsonConvert.SerializeObject(result.ApiUser); ViewBag.ApiUser = json; return(View()); }
public async Task <ApiUser> GetContract([FromRoute] string id) { var token = await _tokenClient.RequestTokenAsync(new TokenSettings { AuthorityBaseUri = Constants.Authority.BaseUri }, Constants.Backend2.ClientId, Constants.Backend2.ClientSecret, new [] { Constants.Backend3.ResourceName }); await _backend3Client.GetProfileAsync("1", token.IdentityToken); return(new ApiUser { Id = Guid.NewGuid().ToString(), Name = "yyyyyy", Age = 10 }); }