Пример #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);
        }