关于#c##的问题,请各位专家解答!

C# WebAPI下Token认证开发问题
需求如下图是这样,需要接口返回Token相关信息

img

类似于单点登录,你提供一个关于授权接口,用于用户用key换取你们系统的token,如果用户的key是你们系统的,则系统内部生成token,并且存入redis,然后将生成的token和存活时间接口返回就好了。
返回格式,自定义json就好了,或者map也行。

using System;
using System.IO;
using System.Net;

class Program
{
    static void Main()
    {
        // URL和JSON数据
        string url = "http://www.abc.com/url"; //这里换成你的真实的地址
        string json = "{\"access_token\":\"xxxxx\",\"token_type\":\"bearer\",\"expires_in\": 3152,\"scope\":\"default\"}";

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/json";

        byte[] postData = System.Text.Encoding.UTF8.GetBytes(json);
        request.ContentLength = postData.Length;

        using (Stream requestStream = request.GetRequestStream())
        {
            requestStream.Write(postData, 0, postData.Length);
        }

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    string responseContent = reader.ReadToEnd();
                    Console.WriteLine(responseContent);
                }
            }
        }
    }
}