Beispiel #1
0
        /**
         * 获取token,适用于获取access_token和刷新token
         *
         * @param accessTokenUrl 实际请求token的地址
         * @return token对象
         */
        private AuthToken getToken(string accessTokenUrl)
        {
            var reqParams = new Dictionary <string, object>
            {
                { "Host", "https://login.microsoftonline.com" },
                { "Content-Type", "application/x-www-form-urlencoded" },
            };

            var reqParamDic       = GlobalAuthUtil.ParseUrlObject(accessTokenUrl);
            var response          = HttpUtils.RequestPost(accessTokenUrl, JsonConvert.SerializeObject(reqParamDic), reqParams);
            var accessTokenObject = response.ParseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.AccessToken  = accessTokenObject.GetString("access_token");
            authToken.TokenType    = accessTokenObject.GetString("token_type");
            authToken.ExpireIn     = accessTokenObject.GetInt32("expires_in");
            authToken.RefreshToken = accessTokenObject.GetString("refresh_token");
            authToken.Scope        = accessTokenObject.GetString("scope");

            return(authToken);
        }