Esempio n. 1
0
        /// <summary>
        /// Verify authorization
        /// </summary>
        /// <param name="authorizationOption">Authorization option</param>
        /// <returns>Return verify authorization reuslt</returns>
        public static async Task <VerifyAuthorizationResult> VerifyAuthorizeAsync(VerifyAuthorizationOption authorizationOption)
        {
            if (authorizationOption == null)
            {
                return(VerifyAuthorizationResult.ForbidResult());
            }
            if (!AuthorizationConfiguration.RemoteVerify)
            {
                if (AuthorizationVerifyProxy == null)
                {
                    throw new ArgumentNullException(nameof(AuthorizationVerifyProxy));
                }
                return(AuthorizationVerifyProxy(authorizationOption) ?? VerifyAuthorizationResult.ForbidResult());
            }
            string server = SelectRemoteVerifyServer();

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

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

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

            return(verifyResult ?? VerifyAuthorizationResult.ForbidResult());
        }
Esempio n. 2
0
 /// <summary>
 /// Verify authorize
 /// </summary>
 /// <param name="authorizationOption">Authorization option</param>
 /// <returns></returns>
 public static VerifyAuthorizationResult VerifyAuthorize(VerifyAuthorizationOption authorizationOption)
 {
     return(VerifyAuthorizeAsync(authorizationOption).Result);
 }