internal CreyRequest(CreyRestClient client, Uri uri, HttpMethod method) { client_ = client; Uri = uri; Method = method; Headers = new List <KeyValuePair <string, string> >(); }
public AccountIdAuthenticationHandler( IOptionsMonitor <AccountIdAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, CreyRestClient creyRestClient) : base(options, logger, encoder, clock) { creyRestClient_ = creyRestClient; }
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})"); } } }
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>()); }
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>()); }
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>()); }