This document explains how developers can use the miri-react-native-sdk to make authorization requests during the token exchange process.
The miri-react-native-sdk supports authorization requests as part of the token exchange flow. When a developer exchanges an SSO token for a Firebase token, they can simultaneously request authorization for external users to access the system.
Authorization requests are validated at the provider level rather than being processed directly from client input. This prevents client-side tampering and ensures that:
Important: Only custom providers support authorization requests. Standard providers (Firebase, Google, Apple) will reject requests containing authorization requests with a 400 Bad Request error.
During token exchange, developers can include an authorization_request in the configuration. The system:
The backend delegates authorization validation to the SSO provider:
After provider validation, the backend automatically:
PERMISSIONS_MEMBER_ADMIN)The SDK supports authorization requests through the ConfigBase interface:
export interface ConfigBase {
api_key?: string;
authorization_request?: {
entries: {
external_uid: string;
}[];
};
}
Important: The authorization_request only includes external_uid values. The system automatically sets default permissions and expiration times.
Authorization requests are only supported by custom providers:
FirebaseConfig - No authorization request supportGoogleConfig - No authorization request supportAppleConfig - No authorization request supportCustomConfig - Full authorization request support and validationNote: If you include an authorization_request with Firebase, Google, or Apple providers, the request will be rejected with a 400 Bad Request error.
import { MiriAppProvider, AuthProvider } from '@miri-ai/miri-react-native';
const miriAuth = {
token: "custom-sso-token",
provider: "custom",
config: {
token_validation_url: "https://your-domain.com/validate",
api_key: "your-api-key",
authorization_request: {
entries: [
{ external_uid: "user123" },
{ external_uid: "user456" }
]
}
}
};
function App() {
return (
<MiriAppProvider
apiKey="your-api-key"
env="production"
>
<AuthProvider miriAuth={miriAuth}>
{/* Your app components */}
</AuthProvider>
</MiriAppProvider>
);
}
Important: Only custom providers support authorization requests. If you try to use authorization requests with Firebase, Google, or Apple providers, your request will be rejected.
For Firebase, Google, and Apple providers, you can only perform basic token exchange without authorization requests:
// Firebase Provider (No Authorization)
const miriAuth = {
token: "firebase-sso-token",
provider: "firebase",
config: {
project_id: "your-firebase-project",
api_key: "your-api-key"
// No authorization_request - will be rejected if included
}
};
// Google Provider (No Authorization)
const miriAuth = {
token: "google-sso-token",
provider: "google",
config: {
client_id: "your-google-client-id",
issuer_url: "https://accounts.google.com",
api_key: "your-api-key"
// No authorization_request - will be rejected if included
}
};
// Apple Provider (No Authorization)
const miriAuth = {
token: "apple-sso-token",
provider: "apple",
config: {
team_id: "your-apple-team-id",
key_id: "your-apple-key-id",
issuer_url: "https://appleid.apple.com",
api_key: "your-api-key"
// No authorization_request - will be rejected if included
}
};
The SDK only requires the external_uid for each authorization entry:
authorization_request: {
entries: [
{ external_uid: "user123" },
{ external_uid: "user456" }
]
}
The backend automatically adds:
# Default permissions
permissions: List[Permissions] = PERMISSIONS_MEMBER_ADMIN
# Default expiration (1 hour from now)
expires_at: datetime = get_utc_now() + timedelta(hours=1)
// Configure authorization request
const authorizationRequest = {
entries: [
{ external_uid: "external-user-1" },
{ external_uid: "external-user-2" }
]
};
// Include in token exchange config (custom provider required for authorization)
const miriAuth = {
token: "sso-token",
provider: "custom",
config: {
token_validation_url: "https://your-domain.com/validate",
api_key: "your-api-key",
authorization_request: authorizationRequest
}
};
// SDK sends request to backend
const response = await exchangeToken(miriAuth);
// POST /api/v2.0/auth/token-exchange
# Backend validates token AND authorization request at provider level
external_uid, token_data, validated_authorization = validator.validate_token_with_authorization(
token,
authorization_request
)
# Backend creates care seeker
care_seeker = create_or_get_care_seeker(external_uid)
# Backend processes ONLY validated authorization request
if validated_authorization:
authorization_records = authorization_service.process_authorization_request(
admin_care_seeker=care_seeker,
authorization_entries=validated_authorization.entries, # ← NOW VALIDATED!
organization_id=organization_id
)
external_uid// When integrating with external patient management systems
// Note: This requires a custom provider for authorization support
const miriAuth = {
token: "admin-sso-token",
provider: "custom", // Custom provider required for authorization
config: {
token_validation_url: "https://your-domain.com/validate",
api_key: "your-api-key",
authorization_request: {
entries: [
{ external_uid: "patient-123" }, // Patient from external system
{ external_uid: "patient-456" } // Another patient
]
}
}
};
// When onboarding multiple users at once
// Note: This requires a custom provider for authorization support
const miriAuth = {
token: "admin-sso-token",
provider: "custom", // Custom provider required for authorization
config: {
token_validation_url: "https://your-domain.com/validate",
api_key: "your-api-key",
authorization_request: {
entries: [
{ external_uid: "new-user-1" },
{ external_uid: "new-user-2" },
{ external_uid: "new-user-3" }
]
}
}
};
// For Firebase, Google, and Apple providers, you can only perform basic authentication
const miriAuth = {
token: "sso-token",
provider: "firebase", // or "google", "apple"
config: {
project_id: "your-project", // or client_id/issuer_url for Google/Apple
api_key: "your-api-key"
// No authorization_request possible with standard providers
}
};
// ❌ Invalid - missing external_uid
authorization_request: {
entries: [
{} // This will cause validation errors
]
}
// ❌ Invalid - empty entries array
authorization_request: {
entries: [] // Backend requires at least one entry
}
// ✅ Valid - proper structure
authorization_request: {
entries: [
{ external_uid: "user123" }
]
}
// ✅ Best - Full validation at your endpoint
provider: "custom",
config: {
token_validation_url: "https://your-domain.com/validate"
}
// ⚠️ Good - Basic validation by Miri
provider: "firebase",
config: {
project_id: "your-project"
}
// ✅ Good - descriptive external UIDs
{ external_uid: "patient-john-doe-123" }
{ external_uid: "user-email@example.com" }
// ❌ Avoid - generic or unclear UIDs
{ external_uid: "user1" }
{ external_uid: "temp-123" }
// ✅ Efficient - batch multiple users in one request
authorization_request: {
entries: [
{ external_uid: "user1" },
{ external_uid: "user2" },
{ external_uid: "user3" }
]
}
try {
const response = await exchangeToken(miriAuth);
// Authorization request processed successfully
} catch (error) {
// Handle authorization or token exchange errors
console.error('Authorization request failed:', error);
}
PERMISSIONS_MEMBER_ADMIN| Provider | Authorization Support | Use Case ||----------|---------------------|----------|| Custom | ✅ Full Support | Multi-user onboarding, external system integration || Firebase | ❌ Not Supported | Single-user authentication only || Google | ❌ Not Supported | Single-user authentication only || Apple | ❌ Not Supported | Single-user authentication only |
The system provides:
Note: If you need authorization request functionality, you must use a custom provider as standard providers do not support this feature.