首页 > 数据库技术 > 详细

在受identityServer4保护的子站点里获得accesstoken的方法

时间:2021-05-26 21:50:01      阅读:26      评论:0      收藏:0      [点我收藏+]

1、在nuget里添加引用

IdentityServer4.AspNetIdentity

 

2、下面的代码能获得accesstoken

            var result = HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken).Result;

详细的引用如下:

using IServices;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DataPoolAdminCenter.Controllers
{
    [Authorize]
    public class SchedulingController : Controller
    {
        IBaseInfoServices _baseInfoServces;
        public SchedulingController(IBaseInfoServices baseInfoServces)
        {
            _baseInfoServces = baseInfoServces;
        }
        public IActionResult Index()
        {
            //这是得到的token
            var token = HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken).Result;

            return View();
        }
    }

 

在受identityServer4保护的子站点里获得accesstoken的方法

原文:https://www.cnblogs.com/wjx-blog/p/14814731.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!