zoukankan      html  css  js  c++  java
  • 在受identityServer4保护的子站点里获得accesstoken的方法

    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();
            }
        }
  • 相关阅读:
    Word Break
    Binary Tree Right Side View
    41. First Missing Positive
    2 Sum ,3 Sum, 3 Sum close
    216. Combination Sum III
    190. Reverse Bits
    143. Reorder List
    142. Linked List Cycle II
    Single Number i,ii,iii
    62. Unique Paths i & ii
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/14814731.html
Copyright © 2011-2022 走看看