Membership
Overview of membership service
CodeMash Membership service provides many operations for user management like user authentication and authorization.
Membership service is enabled automatically when you create a project. This means you can start using membership services and API methods right after you create a project.
Features included in membership service:
  1. 1.
    Users - users of your application.
  2. 2.
    Authentication and authorization - managing user session and permissions.

If you decide to use one of our provided SDK, the following code shows how to initialize membership service.
.NET
Node
PHP
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
var apiKey = "{YOUR_SECRET_KEY}";
โ€‹
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);
โ€‹
use Codemash\CodemashClient;
use Codemash\CodemashDb;
โ€‹
class CodemashService
{
protected CodemashDb $codemashAuth;
โ€‹
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
โ€‹
$client = new CodemashClient('{YOUR_SECRET_KEY}', '{YOUR_PROJECT_ID}');
$codemashAuth = new CodemashAuth($client);
}
}

The following are examples of membership SDK using different languages and frameworks.
.NET
Node
PHP
using System;
using CodeMash.Client;
using CodeMash.Membership.Services;
using Isidos.CodeMash.ServiceContracts;
โ€‹
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
// 1. Get your Project ID and Secret Key
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
var apiKey = "{YOUR_SECRET_KEY}";
โ€‹
// 2. Create a general client for API calls
var client = new CodeMashClient(apiKey, projectId);
// 3. Create a service object
var membershipService = new CodeMashMembershipService(client);
โ€‹
// 4. Call an API method
membershipService.RegisterUser(new RegisterUserRequest
{
Email = "[email protected]",
Password = "password123"
});
}
}
}
โ€‹
use Codemash\CodemashClient;
use Codemash\CodemashAuth;
โ€‹
class CodemashService
{
protected CodemashAuth $codemashAuth;
โ€‹
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
โ€‹
$client = new CodemashClient($secretKey, $projectId);
$this->codemashAuth = new CodemashAuth($client);
}
โ€‹
public function login()
{
$responseData = $this->codemashAuth->authenticate([
'userName' => '[email protected]',
'password' => 'password123',
]);
}
}

The following links explore the usage of membership service:
Copy link
On this page
Using SDK
Example
Working with Membership Service