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.

Using SDK

If you decide to use one of our provided SDK, the following code shows how to initialize membership service.
.NET
Node
PHP
1
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
2
var apiKey = "{YOUR_SECRET_KEY}";
3
4
var client = new CodeMashClient(apiKey, projectId);
5
var membershipService = new CodeMashMembershipService(client);
Copied!
1
Copied!
1
use Codemash\CodemashClient;
2
use Codemash\CodemashDb;
3
4
class CodemashService
5
{
6
protected CodemashDb $codemashAuth;
7
8
public function __construct()
9
{
10
$secretKey = '{YOUR_SECRET_KEY}';
11
$projectId = '{YOUR_PROJECT_ID}';
12
13
$client = new CodemashClient('{YOUR_SECRET_KEY}', '{YOUR_PROJECT_ID}');
14
$codemashAuth = new CodemashAuth($client);
15
}
16
}
Copied!

Example

The following are examples of membership SDK using different languages and frameworks.
.NET
Node
PHP
1
using System;
2
using CodeMash.Client;
3
using CodeMash.Membership.Services;
4
using Isidos.CodeMash.ServiceContracts;
5
6
namespace ConsoleApplication
7
{
8
class Program
9
{
10
static void Main(string[] args)
11
{
12
// 1. Get your Project ID and Secret Key
13
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
14
var apiKey = "{YOUR_SECRET_KEY}";
15
16
// 2. Create a general client for API calls
17
var client = new CodeMashClient(apiKey, projectId);
18
19
// 3. Create a service object
20
var membershipService = new CodeMashMembershipService(client);
21
22
// 4. Call an API method
23
membershipService.RegisterUser(new RegisterUserRequest
24
{
25
Email = "[email protected]",
26
Password = "password123"
27
});
28
}
29
}
30
}
Copied!
1
Copied!
1
use Codemash\CodemashClient;
2
use Codemash\CodemashAuth;
3
4
class CodemashService
5
{
6
protected CodemashAuth $codemashAuth;
7
8
public function __construct()
9
{
10
$secretKey = '{YOUR_SECRET_KEY}';
11
$projectId = '{YOUR_PROJECT_ID}';
12
13
$client = new CodemashClient($secretKey, $projectId);
14
$this->codemashAuth = new CodemashAuth($client);
15
}
16
17
public function login()
18
{
19
$responseData = $this->codemashAuth->authenticate([
20
'userName' => '[email protected]',
21
'password' => 'password123',
22
]);
23
}
24
}
Copied!

Working with Membership Service

The following links explore the usage of membership service:
Last modified 1yr ago