|
|
|
@ -1,37 +1,15 @@
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using IdentityModel.Client;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Yavsc.WebApiClient.Helpers;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace testOauthClient.Controllers
|
|
|
|
namespace sampleWebAsWebApiClient.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class HomeController : Controller
|
|
|
|
public class HomeController(ILoggerFactory loggerFactory) : Controller
|
|
|
|
{
|
|
|
|
{
|
|
|
|
readonly ILogger _logger;
|
|
|
|
readonly ILogger _logger = loggerFactory.CreateLogger<HomeController>();
|
|
|
|
|
|
|
|
|
|
|
|
public class GCMRegistrationRecord
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public string GCMRegistrationId { get; set; } = "testGoogleRegistrationIdValue";
|
|
|
|
|
|
|
|
public string DeviceId { get; set; } = "TestDeviceId";
|
|
|
|
|
|
|
|
public string Model { get; set; } = "TestModel";
|
|
|
|
|
|
|
|
public string Platform { get; set; } = "External Web";
|
|
|
|
|
|
|
|
public string Version { get; set; } = "0.0.1-rc1";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public HomeController(ILoggerFactory loggerFactory)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger = loggerFactory.CreateLogger<HomeController>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
public IActionResult Index()
|
|
|
|
public IActionResult Index()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -49,36 +27,22 @@ namespace testOauthClient.Controllers
|
|
|
|
ViewBag.Json = content;
|
|
|
|
ViewBag.Json = content;
|
|
|
|
return View("json");
|
|
|
|
return View("json");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<IActionResult> GetUserInfo(CancellationToken cancellationToken)
|
|
|
|
public async Task<IActionResult> GetUserInfo(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var accessToken = await HttpContext.GetTokenAsync("access_token");
|
|
|
|
var accessToken = await HttpContext.GetTokenAsync("access_token");
|
|
|
|
var client = new HttpClient(new HttpClientHandler(){ AllowAutoRedirect=false });
|
|
|
|
|
|
|
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
|
|
string json = await HttpContext.GetJson("https://localhost:6001/api/account/me");
|
|
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
|
|
|
return View("UserInfo", json);
|
|
|
|
var content = await client.GetAsync("https://localhost:6001/api/account/me");
|
|
|
|
|
|
|
|
content.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
var json = await content.Content.ReadAsStreamAsync();
|
|
|
|
|
|
|
|
var obj = JsonSerializer.Deserialize<JsonElement>(json);
|
|
|
|
|
|
|
|
return View("UserInfo", obj.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<IActionResult> GetApiCall(CancellationToken cancellationToken)
|
|
|
|
public async Task<IActionResult> GetIdentity(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var accessToken = await HttpContext.GetTokenAsync("access_token");
|
|
|
|
string json = await HttpContext.GetJson("https://localhost:6001/identity");
|
|
|
|
var client = new HttpClient(new HttpClientHandler(){ AllowAutoRedirect=false });
|
|
|
|
|
|
|
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
|
|
|
|
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
|
|
|
|
|
|
|
var content = await client.GetAsync("https://localhost:6001/identity");
|
|
|
|
|
|
|
|
content.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
var json = await content.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
return View("UserInfo", json);
|
|
|
|
return View("UserInfo", json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult About()
|
|
|
|
public IActionResult About()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ViewData["Message"] = "Your application description page.";
|
|
|
|
ViewData["Message"] = "Your application description page.";
|
|
|
|
|