Esempio n. 1
0
        /// <summary>
        /// Authorize
        /// </summary>
        /// <param name="authorizeOptions">Authorize options</param>
        /// <returns>Return the authorize reuslt</returns>
        public static async Task <AuthorizeResult> AuthorizeAsync(AuthorizeOptions authorizeOptions)
        {
            if (authorizeOptions == null)
            {
                return(AuthorizeResult.ForbidResult());
            }
            if (!AuthorizationConfiguration.RemoteVerify)
            {
                if (AuthorizeProxy == null)
                {
                    throw new ArgumentNullException(nameof(AuthorizeProxy));
                }
                return(AuthorizeProxy(authorizeOptions) ?? AuthorizeResult.ForbidResult());
            }
            string server = SelectRemoteServer();

            if (string.IsNullOrWhiteSpace(server))
            {
                throw new ArgumentNullException(nameof(AuthorizationConfiguration.Servers));
            }
            var result = await HttpHelper.PostJsonAsync(server, authorizeOptions).ConfigureAwait(false);

            var stringValue = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

            AuthorizeResult verifyResult = JsonSerializeHelper.JsonToObject <AuthorizeResult>(stringValue);

            return(verifyResult ?? AuthorizeResult.ForbidResult());
        }
Esempio n. 2
0
 /// <summary>
 /// Authorize
 /// </summary>
 /// <param name="authorizeOptions">Authorize options</param>
 /// <returns>Return the authorize reuslt</returns>
 public static AuthorizeResult Authorize(AuthorizeOptions authorizeOptions)
 {
     return(AuthorizeAsync(authorizeOptions).Result);
 }