コード例 #1
0
 internal CreyRequest(CreyRestClient client, Uri uri, HttpMethod method)
 {
     client_ = client;
     Uri     = uri;
     Method  = method;
     Headers = new List <KeyValuePair <string, string> >();
 }
コード例 #2
0
 public AccountIdAuthenticationHandler(
     IOptionsMonitor <AccountIdAuthenticationOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     CreyRestClient creyRestClient)
     : base(options, logger, encoder, clock)
 {
     creyRestClient_ = creyRestClient;
 }
コード例 #3
0
        public static async Task ValidateContentAccessRightAsync(this CreyRestClient creyRestClient, UserInfo userInfo, int contentOwnerId)
        {
            if (userInfo.AccountId != contentOwnerId)
            {
                if (userInfo.AccountId == 0)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Unauthorized, "Login required");
                }
                // from this point only ContentDev role is required for the logged in user
                if (!userInfo.Roles.Contains(UserRoles.ContentDev))
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Unauthorized, "Content dev role required");
                }
                // both user (requesting and owner) are content dev
                var contentOwner = await creyRestClient.GetUserInfoAsync(contentOwnerId);

                if (!contentOwner.Roles.Contains(UserRoles.ContentDev))
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Unauthorized, $"Cannot acces content of owner ({contentOwnerId}) as user has no ContentDev role ({contentOwner}). (You have: {userInfo.AccountId})");
                }
            }
        }
コード例 #4
0
        public static Task <SessionInfo> ImpersonateAccount(this CreyRestClient creyClient, int accountId)
        {
            var request = creyClient.CreateRequest(HttpMethod.Post, IAM_SERVICE_NAME, $"/iam/s2s/accounts/{accountId}/signin").AddS2SHeader();

            return(request.SendAndParseAsync <SessionInfo>());
        }
コード例 #5
0
        public static Task <UserInfo> GetUserInfoAsync(this CreyRestClient creyClient, int accountId)
        {
            var request = creyClient.CreateRequest(HttpMethod.Get, IAM_SERVICE_NAME, $"/iam/s2s/accounts/{accountId}/roles").AddS2SHeader();

            return(request.SendAndParseAsync <UserInfo>());
        }
コード例 #6
0
        public static Task <Result <SessionInfo, HttpResponseMessage> > ValidateKeyAsync(this CreyRestClient creyClient, string key, string userAgent)
        {
            var request = creyClient.CreateRequest(HttpMethod.Post, IAM_SERVICE_NAME, "/iam/s2s/accounts/validate/key").AddS2SHeader();

            if (!string.IsNullOrEmpty(userAgent))
            {
                request.AddUserAgentHeader(userAgent);
            }

            request.SetContentJsonBody(new CheckKeyParams {
                Key = key
            });
            return(request.SendAndTryParseAsync <SessionInfo>());
        }