curl --request POST \
--url https://api.example.com/api/auth/register \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>",
"name": "<string>",
"organization": "<string>",
"country": "<string>"
}
'{
"user_id": "<string>",
"email": "<string>",
"email_verified": true,
"name": "<string>",
"message": "<string>",
"verification_required": true
}Register new users in AWS Cognito User Pool
curl --request POST \
--url https://api.example.com/api/auth/register \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>",
"name": "<string>",
"organization": "<string>",
"country": "<string>"
}
'{
"user_id": "<string>",
"email": "<string>",
"email_verified": true,
"name": "<string>",
"message": "<string>",
"verification_required": true
}[email protected]SecureP@ssw0rd123John DoeIGAD Climate Prediction and Applications CentreKenya{
"email": "[email protected]",
"password": "SecureP@ssw0rd123",
"name": "John Doe",
"organization": "IGAD ICPAC",
"country": "Kenya"
}
false on registration. User must verify email via code.true. Indicates user must verify email before login.{
"user_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"email": "[email protected]",
"email_verified": false,
"name": "John Doe",
"message": "Registration successful. Please check your email for verification code.",
"verification_required": true
}
{
"detail": "An account with this email already exists"
}
UsernameExistsException
{
"detail": "Password does not meet requirements: Must contain uppercase, lowercase, number, and special character"
}
InvalidPasswordException
{
"detail": "Invalid email format"
}
InvalidParameterException
{
"detail": "Too many registration attempts. Please try again later."
}
TooManyRequestsException
{
"detail": "Registration failed: {error_message}"
}
sign_up API:
from botocore.exceptions import ClientError
import boto3
cognito_client = boto3.client('cognito-idp', region_name='us-east-1')
try:
response = cognito_client.sign_up(
ClientId=os.getenv('COGNITO_CLIENT_ID'),
Username=email,
Password=password,
UserAttributes=[
{'Name': 'email', 'Value': email},
{'Name': 'name', 'Value': name},
{'Name': 'custom:organization', 'Value': organization},
{'Name': 'custom:country', 'Value': country},
]
)
user_id = response['UserSub']
except ClientError as e:
error_code = e.response['Error']['Code']
# Handle specific errors
/api/auth/verify-email with:
emailcode/api/auth/logincustom:organization (String, mutable)custom:country (String, mutable)custom:role (String, mutable) - Default: “user”if email.endswith('@igad.int'):
# Auto-confirm for internal users
cognito_client.admin_confirm_sign_up(
UserPoolId=os.getenv('COGNITO_USER_POOL_ID'),
Username=user_id
)
{
"email": "[email protected]",
"code": "123456"
}
{
"success": true,
"message": "Email verified successfully. You can now log in.",
"email_verified": true
}
cognito_client.confirm_sign_up(
ClientId=os.getenv('COGNITO_CLIENT_ID'),
Username=email,
ConfirmationCode=code
)
{
"email": "[email protected]"
}
{
"success": true,
"message": "Verification code resent. Check your email.",
"delivery": {
"DeliveryMedium": "EMAIL",
"Destination": "n***@igad.int"
}
}
cognito_client.resend_confirmation_code(
ClientId=os.getenv('COGNITO_CLIENT_ID'),
Username=email
)
// Step 1: Register
const registerResponse = await fetch('https://api.igad.int/api/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '[email protected]',
password: 'SecureP@ssw0rd123',
name: 'John Doe',
organization: 'IGAD ICPAC',
country: 'Kenya',
}),
})
const registerData = await registerResponse.json()
if (registerResponse.ok) {
console.log('Registration successful:', registerData.message)
// Step 2: Prompt user for verification code
const verificationCode = prompt('Enter verification code from email:')
// Step 3: Verify email
const verifyResponse = await fetch('https://api.igad.int/api/auth/verify-email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '[email protected]',
code: verificationCode,
}),
})
const verifyData = await verifyResponse.json()
if (verifyResponse.ok) {
console.log('Email verified. You can now log in.')
// Redirect to login page
}
} else {
console.error('Registration failed:', registerData.detail)
}
import requests
# Step 1: Register
register_response = requests.post(
'https://api.igad.int/api/auth/register',
json={
'email': '[email protected]',
'password': 'SecureP@ssw0rd123',
'name': 'John Doe',
'organization': 'IGAD ICPAC',
'country': 'Kenya'
}
)
if register_response.status_code == 201:
print("Registration successful. Check email for verification code.")
# Step 2: Verify email (after receiving code)
verification_code = input("Enter verification code: ")
verify_response = requests.post(
'https://api.igad.int/api/auth/verify-email',
json={
'email': '[email protected]',
'code': verification_code
}
)
if verify_response.status_code == 200:
print("Email verified. You can now log in.")
else:
print(f"Registration failed: {register_response.json()['detail']}")
aws cognito-idp admin-create-user \
--user-pool-id $COGNITO_USER_POOL_ID \
--username [email protected] \
--user-attributes Name=email,[email protected] Name=name,Value="John Doe" \
--temporary-password TempP@ssw0rd123 \
--message-action SUPPRESS
NEW_PASSWORD_REQUIRED challenge.POST /api/auth/register endpointPOST /api/auth/verify-email endpointPOST /api/auth/resend-verification endpoint