public object Any(HelloCreateRequest Request) { new NhibernateManager().CreateDatabase(); foreach (HelloCreateRequest.Object user in Request.user) { JsonServiceClient client = new JsonServiceClient(); client.AddHeader("API-Key", "Android"); client.Post <BaseResponse>("http://127.0.0.1:8080/api/1.5/user", new PostUserRequest() { facebookToken = user.facebookToken } ); client.AddHeader("Auth-Key", user.facebookToken); client.Get <GetEventsResponse>("http://127.0.0.1:8080/api/1.5/events"); client.Put <BaseResponse>("http://127.0.0.1:8080/api/1.5/user/preferences", new PutUserPreferencesRequest() { ageEnd = user.ageEnd, ageStart = user.ageStart, gender = user.gender } ); } return(new BaseResponse()); }
private static JsonServiceClient CreateClient(string baseUrl, string token) { var client = new JsonServiceClient(baseUrl.TrimEnd('/')); client.AddHeader(HttpHeaders.Authorization, @"Bearer {0}".Fmt(token)); return client; }
public static void GenerateRootCertificate(string rootToken, string cn, string ttl) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); var result = client.Post <JsonObject>("v1/pki/root/generate/internal", new { common_name = cn, ttl }); } }
public static void GetCertificateUrlConfiguration(string rootToken) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); var response = client.Get <JsonObject>("v1/pki/config/urls"); } }
private static JsonServiceClient CreateClient(string baseUrl, string token) { var client = new JsonServiceClient(baseUrl.TrimEnd('/')); client.AddHeader(HttpHeaders.Authorization, @"Bearer {0}".Fmt(token)); return(client); }
public static void MountTunePki(string rootToken) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>("v1/sys/mounts/pki/tune", new { max_lease_ttl = "87600h" }); } }
public static JsonServiceClient AddHeaders(this JsonServiceClient client, Dictionary <string, string> headers) { foreach (var header in headers) { client.AddHeader(header.Key, header.Value); } return(client); }
protected override ICachedServiceClient GetCachedServiceClient() { var client = new JsonServiceClient(Config.ListeningOn); #if NETCORE client.AddHeader(HttpHeaders.AcceptEncoding, "gzip,deflate"); #endif return new CachedServiceClient(client); }
public static void MountPki(string rootToken) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>("v1/sys/mounts/pki", new { type = "pki" }); } }
public static void CreatePolicy(string rootToken, string name, string path, string policy) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Put <string>($"v1/sys/policy/{name}", new { rules = CreateRule(path, policy).ToJson() }); } }
public static void EnableAppId(string rootToken) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>("v1/sys/auth/app-id", new { type = "app-id" }); } }
public static void CreateAppId(string rootToken, string appId, string policy) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Put <string>($"v1/auth/app-id/map/app-id/{appId}", new { value = policy }); } }
protected override ICachedServiceClient GetCachedServiceClient() { var client = new JsonServiceClient(Config.ListeningOn); #if NETCORE client.AddHeader(HttpHeaders.AcceptEncoding, "gzip,deflate"); #endif return(new CachedServiceClient(client)); }
public Task <List <RouteDTO> > GetAllRoutes() { var client = new JsonServiceClient(BaseUrl); client.AddHeader("Authorization", "Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="); var result = client.GetAsync <List <RouteDTO> >("/api/Route/GetAll"); return(result); }
public Task Unsubscribe(int subscriptionId) { var client = new JsonServiceClient(BaseUrl); client.AddHeader("Authorization", "Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="); var result = client.DeleteAsync <SubscriptionDTO>($"/api/Subscription/Unsubscribe/{subscriptionId}"); return(result); }
public Task <List <SubscriptionDTO> > GetUserSubscription(int userId) { var client = new JsonServiceClient(BaseUrl); client.AddHeader("Authorization", "Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="); var result = client.GetAsync <List <SubscriptionDTO> >($"/api/subscription/UserSubscriptions/{userId}"); return(result); }
public Task <SubscriptionDTO> Subscribe(SubscriptionDTO subscriptionDTO) { var client = new JsonServiceClient(BaseUrl); client.AddHeader("Authorization", "Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="); var result = client.PostAsync <SubscriptionDTO>("/api/Subscription", subscriptionDTO); return(result); }
public static void CreateSecrets(string rootToken, string secretName, string[] secrets) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>($"v1/secret/{secretName}", new { value = Encoding.UTF8.GetBytes(secrets.ToJson()) }); } }
//const string ApiUrlProd = "https://api.bokamera.se/"; static void Main(string[] args) { AuthExamples(); // Create and configure client // BokaMera API supports MsgPack, prefer that for efficient communication with the API. // See https://github.com/ServiceStack/ServiceStack/wiki/MessagePack-Format // See https://github.com/ServiceStack/ServiceStack/wiki/C%23-client var client = new JsonServiceClient(ApiUrlTest); client.Headers.Add("x-api-key", "YOUR_API_KEY_HERE"); //Language settings sv = swedish, en = english (default) client.Headers.Add("x-language", "sv"); //Authenticate the user var response = client.Post <AuthenticateResponse>("authenticate", new { UserName = "******", Password = "******", }); client.AddHeader("x-ss-id", response.SessionId); client.BearerToken = response.BearerToken; // Call service, this uses Dto from BokaMera's nuget package to return typed responses. // Check the namespace BokaMera.API.ServiceModel.Dto.* for request and response classes Console.WriteLine("Calling service GetApiVersion..."); var versionResponse = client.Get(new ApiVersionQuery()); //Create request object for retrieving bookings var request = new BookingQuery { Id = 370476 }; //Retrieve the bookings. To see what return type see the https://testapi.bokamera.se/swagger-ui/#!/bookings/BookingQuery QueryResponse <BookingQueryResponse> bookings = client.Get <QueryResponse <BookingQueryResponse> >(request); // Print response Console.WriteLine("Response received, printing output..."); response.PrintDump(); // Logout session Console.WriteLine("Logging out...press any key to quit"); client.Post(new Authenticate { provider = "logout" }); // Wait for keypress Console.ReadKey(); }
public static void GenerateCertificateRole(string rootToken, string roleName, string domains) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>($"v1/pki/roles/{roleName}", new { allowed_domains = domains, allow_subdomains = true, max_ttl = "72h" }); } }
public static void MapUserIdsToAppIds(string rootToken, string userId, params string[] appIds) { if (appIds == null || appIds.Length == 0) { throw new Exception("user-id needs to be associated with at least 1 app-id"); } using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>($"v1/auth/app-id/map/user-id/{userId}", new { value = appIds.Join(",") }); } }
public static void SetCertificateUrlConfiguration(string rootToken) { using (var client = new JsonServiceClient(VaultUriInstance)) { client.AddHeader("X-Vault-Token", rootToken); client.Post <JsonObject>("v1/pki/config/urls", new { issuing_certificates = $"{VaultUriInstance}/v1/pki/ca", crl_distribution_points = $"{VaultUriInstance}/v1/pki/crl" }); } }
public UserDTO AreUserAndPasswordValid(string user, string password) { var client = new JsonServiceClient(BaseUrl); client.AddHeader("Authorization", "Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="); var result = client.Post <UserDTO>("/api/Users/LoginUser", new { Name = user, Password = password }); return(result); }
public void PostBookingAsAdminExample() { // Create and configure client // BokaMera API supports MsgPack, prefer that for efficient communication with the API. // See https://github.com/ServiceStack/ServiceStack/wiki/MessagePack-Format // See https://github.com/ServiceStack/ServiceStack/wiki/C%23-client var client = new JsonServiceClient(ApiUrlTest); client.Headers.Add("x-api-key", "YOUR_API_KEY_HERE"); //Language settings sv = swedish, en = english (default) client.Headers.Add("x-language", "sv"); //Authenticate the user var response = client.Post <AuthenticateResponse>("authenticate", new { UserName = "******", //The user is administrator for Company Demo Hårsalong with CompanyId: 00000000-0000-0000-0000-000000000001 (see https://www.bokamera.se/Demo1) Password = "******", }); client.AddHeader("x-ss-id", response.SessionId); client.BearerToken = response.BearerToken; //Create request object for create a new booking var request = new CreateBooking { CompanyId = new Guid("00000000-0000-0000-0000-000000000001"), CustomerId = new Guid("00000000-0000-0000-0000-000000000010"), From = DateTime.Now, To = DateTime.Now.AddMinutes(60), AllowBookingOutsideSchedules = true, ServiceId = 1, //Klippning , kort hår - Kortbetalning (see https://www.bokamera.se/Demo1/BookTime?event=1) Resources = new System.Collections.Generic.List <ResourceToBook>() { new ResourceToBook() { ResourceId = 1, ResourceTypeId = 1 }, new ResourceToBook() { ResourceId = 5, ResourceTypeId = 2 }, } }; }
static void GetBookingsExample() { // Create and configure client // BokaMera API supports MsgPack, prefer that for efficient communication with the API. // See https://github.com/ServiceStack/ServiceStack/wiki/MessagePack-Format // See https://github.com/ServiceStack/ServiceStack/wiki/C%23-client var client = new JsonServiceClient(ApiUrlTest); client.Headers.Add("x-api-key", "YOUR_API_KEY_HERE"); //Language settings sv = swedish, en = english (default) client.Headers.Add("x-language", "sv"); //Authenticate the user var response = client.Post <AuthenticateResponse>("authenticate", new { UserName = "******", Password = "******", }); client.AddHeader("x-ss-id", response.SessionId); client.BearerToken = response.BearerToken; //Create request object for retrieving bookings //See https://github.com/ServiceStack/ServiceStack/wiki/AutoQuery-RDBMS How to query on columns var request = new BookingQuery { CompanyBookings = true //Get All bookings for the company you are administrator for (the authenticated user) //Id = 370476, //Get a specific booking with the BookingId //IncludeBookedResources = true, //Include all booked resource information //IncludeCompanyInformation = true, //Include the company information for the booking //IncludeCustomerInformation = true, //Include the customer information for the booking //IncludeCustomFields = true, //Include the custom fields for the booking if any exists //IncludeLog = true, //Include the booking log (only allowed for adminstrators //IncludeCustomFieldValues = true, //Include the selected values for the custom fields, if any exists //IncludeServiceInformation = true, //Include the service information for the booking //BookingStart = new DateTime(2017, 01, 01), //Will query bookings that are between BookingStart and BookingEnd (Default for BookingStart is DateTime.MinValue) //BookingEnd = new DateTime(2017, 01, 01), //Will query bookings that are between BookingStart and BookingEnd (Default for BookingStart is DateTime.MaxValue) //StatusIds = new int[] { 1, 2, 3 }, //Will get all bookings with the status 1,2 or 3 //Take = 10, //Will get at most 10 bookings (user for paging) //Skip = 5, //Will skip 5 bookings (user for paging) //OrderBy = "Id", //will order bookings by the property Id Asceding //OrderByDesc = "Id" //Will order bookings by the property Id Descending }; // Call service, this uses Dto from BokaMera's nuget package to return typed responses. // Check the namespace BokaMera.API.ServiceModel.Dto.* for request and response classes //Retrieve the bookings. To see what return type see the https://testapi.bokamera.se/swagger-ui/#!/bookings/BookingQuery QueryResponse <BookingQueryResponse> bookings = client.Get <QueryResponse <BookingQueryResponse> >(request); // Print response Console.WriteLine("Response received, printing output..."); response.PrintDump(); // Logout session Console.WriteLine("Logging out...press any key to quit"); client.Post(new Authenticate { provider = "logout" }); // Wait for keypress Console.ReadKey(); }