如何解决用用户模型填充模型
我正在使用oauth策略,该策略从dotnet填充内置用户模型。现在,我想用此用户模型填充自己的模型,然后还从我使用oauth的第三方服务提供的API中获取更多信息。现在,我有点困惑如何用用户填充我自己的模型。我应该怎么做。侧面是使用MVC结构。
控制器
namespace AspNetCoreGitHubAuth.Controllers
{
[Authorize]
[Route("[controller]/[action]")]
public class TestController : Controller
{
[HttpGet]
public ActionResult Welcome()
{
Console.WriteLine("---------------------");
return View();
}
Welcome.cshtml
@{
ViewData["Title"] = "test welcome";
}
// i want to display the user info on this page
<h2>test welcome</h2>
模型
namespace AspNetCoreGitHubAuth.Models
{
public class Github
{
public class IndexModel
{
public string GitHubAvatar { get; set; }
public string GitHubLogin { get; set; }
public string GitHubName { get; set; }
public string GitHubUrl { get; set; }
public IReadOnlyList<Repository> Repositories { get; set; }
//public async Task OnGetAsync()
//{
/*if (User.Identity.IsAuthenticated)
{
GitHubName = User.FindFirst(c => c.Type == ClaimTypes.Name)?.Value;
GitHubLogin = User.FindFirst(c => c.Type == "urn:github:login")?.Value;
GitHubUrl = User.FindFirst(c => c.Type == "urn:github:url")?.Value;
GitHubAvatar = User.FindFirst(c => c.Type == "urn:github:avatar")?.Value;
string accessToken = await HttpContext.GetTokenAsync("access_token");
var github = new GitHubClient(new ProductHeaderValue("AspNetCoreGitHubAuth"),new InMemoryCredentialStore(new Credentials(accessToken)));
Repositories = await github.Repository.GetAllForCurrent();
}*/
//}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。