Skip to content

Auth

Introduction

The Auth api controls access to the system. Read more about our authentication architecture here.

Events

This service emits events. To learn more about events here.

auth_updated

When the authentication state changes; auth_updated is emitted.

{
"method": "switchContexts",
"data": {
"user": {
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
},
"business": {
"_id": "c52abc50-b499-11ea-a48c-0100f1a50c6e",
"business_name": "Avengers",
"address_1": "TOP_SECRET",
"address_2": "TOP_SECRET",
"address_3": "New York",
"address_4": null,
"post_code": "TOP_SECRET",
"currency": "usd",
"vat_code": "123",
"invoice_name": "123",
"country_code": "USA",
"contact_name": "Anthony Stark",
"contact_email": "t.stark@avengers.org",
"contact_no": "(970) 517-1743 x67916",
"website": "https://avengers.org",
"logo": "https://assets.avengers.org/images/logo.png",
"requires_gln": false,
"gs1_prefix": "123",
"slug": "avengers",
"external": false,
"public": true
},
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJidXNpbmVzc191dWlkIjoiYzUyYWJjNTAtYjQ5OS0xMWVhLWE0OGMtMDEwMGYxYTUwYzZlIiwiZXhwIjoiMTU5MjkzMDY0MCJ9.e4uj4pCw3qDZqrmWL3ylhThtIEWNAnVnwQOUz67sGys",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJidXNpbmVzc191dWlkIjoiYzUyYWJjNTAtYjQ5OS0xMWVhLWE0OGMtMDEwMGYxYTUwYzZlIiwiZXhwIjoiMTU5Mjg0MzcwMCJ9.Yapd6upCu_bFHP983WXdbtz5kg2L6lcz_tVp2cSTuOM"
}
}

auth_deleted

When the authentication state is revoked; auth_deleted is emitted.

{
"method": "logout"
}

claim_required

When an API reports that a specified claim is required to access it; claim_required is emitted.

{
"claim": "billing:manage"
}

claim_granted

When a user is granted a claim by successfully confirming their credentials; claim_granted is emitted.

{
"claim": "billing:manage"
}

claim_rejected

When a user's attempt to confirm their credentials fails; claim_rejected is emitted.

{
"code": 401,
"message": "Challenge Attempt Failed.",
"attempts": 1,
"max_attempts": 5,
"reason": {
"password": [
"Password not valid"
]
}
}

Invalid credentials

{
"code": 429,
"message": "Too many challenge attempts. You may retry 4 minutes, 57 seconds from now.",
"attempts": 5,
"remaining_ttl": 298
}

Too many challenge attempts.

Properties

business

Gets the current business context.

{
"_id": "c52abc50-b499-11ea-a48c-0100f1a50c6e",
"business_name": "Avengers",
"address_1": "TOP_SECRET",
"address_2": "TOP_SECRET",
"address_3": "New York",
"address_4": null,
"post_code": "TOP_SECRET",
"currency": "usd",
"vat_code": "123",
"invoice_name": "123",
"country_code": "USA",
"contact_name": "Anthony Stark",
"contact_email": "t.stark@avengers.org",
"contact_no": "(970) 517-1743 x67916",
"website": "https://avengers.org",
"logo": "https://assets.avengers.org/images/logo.png",
"requires_gln": false,
"gs1_prefix": "123",
"slug": "avengers",
"external": false,
"public": true
}

user

Gets the logged in user.

{
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
}

Usage

login

Parameters

PropertyTypeRequiredExample
emailStringt.stark@avengers.org
passwordStringizJ7Y0MBwcJ8
realmStringAPI_GATEWAY

Usage

await Xedi.Auth.login('t.stark@avengers.org', 'izJ7Y0MBwcJ8', 'API_GATEWAY');

Events

Emits auth_updated on successful authentication.

Response

{
"method": "switchContexts",
"data": {
"user": {
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
},
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyOTMwNjQwIn0.i1ClUUwYB-O9Q1u-u2J9bCu58YFdGJ4ZC8yXl9CGTsg",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzcifQ.zct6dNkNq8QMSvgq4fcYLRyXZTIhVU3QJ2R6oSZorFU"
}
}

withToken

Parameters

PropertyTypeRequiredExample
refreshTokenStringeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyOTMwNjQwIn0.i1ClUUwYB-O9Q1u-u2J9bCu58YFdGJ4ZC8yXl9CGTsg

Usage

const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyOTMwNjQwIn0.i1ClUUwYB-O9Q1u-u2J9bCu58YFdGJ4ZC8yXl9CGTsg";
await Xedi.Auth.withToken(token);

Events

Emits auth_updated on successful authentication.

Response

{
"method": "switchContexts",
"data": {
"user": {
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
},
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyOTMwNjQwIn0.i1ClUUwYB-O9Q1u-u2J9bCu58YFdGJ4ZC8yXl9CGTsg",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyODQzNzAwIn0.OQcWEyCGNz_oNQGe0BAOgOq4GwIOXH3kevoCpj7sp5w"
}
}

refreshAccessToken

Parameters

null

Usage

await Xedi.Auth.refreshAccessToken();

Events

Emits auth_updated on successful renewal of the authentication state.

Response

{
"method": "switchContexts",
"data": {
"user": {
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
},
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyOTMwNjQwIn0.i1ClUUwYB-O9Q1u-u2J9bCu58YFdGJ4ZC8yXl9CGTsg",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJleHAiOiIxNTkyODQzNzAwIn0.OQcWEyCGNz_oNQGe0BAOgOq4GwIOXH3kevoCpj7sp5w"
}
}

switchContexts

Parameters

PropertyTypeRequiredExample
business_uuidString92ac7274-9369-11ea-9521-01002da17977

Usage

await Xedi.Auth.switchContexts('92ac7274-9369-11ea-9521-01002da17977');

Events

Emits auth_updated on successful updating of the authentication context.

Response

{
"method": "switchContexts",
"data": {
"user": {
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
},
"business": {
"_id": "c52abc50-b499-11ea-a48c-0100f1a50c6e",
"business_name": "Avengers",
"address_1": "TOP_SECRET",
"address_2": "TOP_SECRET",
"address_3": "New York",
"address_4": null,
"post_code": "TOP_SECRET",
"currency": "usd",
"vat_code": "123",
"invoice_name": "123",
"country_code": "USA",
"contact_name": "Anthony Stark",
"contact_email": "t.stark@avengers.org",
"contact_no": "(970) 517-1743 x67916",
"website": "https://avengers.org",
"logo": "https://assets.avengers.org/images/logo.png",
"requires_gln": false,
"gs1_prefix": "123",
"slug": "avengers",
"external": false,
"public": true
},
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJidXNpbmVzc191dWlkIjoiYzUyYWJjNTAtYjQ5OS0xMWVhLWE0OGMtMDEwMGYxYTUwYzZlIiwiZXhwIjoiMTU5MjkzMDY0MCJ9.e4uj4pCw3qDZqrmWL3ylhThtIEWNAnVnwQOUz67sGys",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJidXNpbmVzc191dWlkIjoiYzUyYWJjNTAtYjQ5OS0xMWVhLWE0OGMtMDEwMGYxYTUwYzZlIiwiZXhwIjoiMTU5Mjg0MzcwMCJ9.Yapd6upCu_bFHP983WXdbtz5kg2L6lcz_tVp2cSTuOM"
}
}

requestClaim

Request a claim be added to your tokens by confirming your credentials.

Parameters

PropertyTypeRequiredExample
claimStringbilling:manage
passwordStringsuper-secret-password

Events

Emits auth_updated and claim_granted on success. Emits claim_rejected on failure.

Usage

Xedi.Auth.requestClaim('billing:manage', 'super-secret-password');

Response

{
"user": {
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
},
"business": {
"_id": "c52abc50-b499-11ea-a48c-0100f1a50c6e",
"business_name": "Avengers",
"address_1": "TOP_SECRET",
"address_2": "TOP_SECRET",
"address_3": "New York",
"address_4": null,
"post_code": "TOP_SECRET",
"currency": "usd",
"vat_code": "123",
"invoice_name": "123",
"country_code": "USA",
"contact_name": "Anthony Stark",
"contact_email": "t.stark@avengers.org",
"contact_no": "(970) 517-1743 x67916",
"website": "https://avengers.org",
"logo": "https://assets.avengers.org/images/logo.png",
"requires_gln": false,
"gs1_prefix": "123",
"slug": "avengers",
"external": false,
"public": true
},
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlzcyI6Imh0dHBzOi8vYXBpLnhlZGkuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkueGVkaS5jb20ifQ.eyJ1c2VyX3V1aWQiOiI5MmFjNzI3NC05MzY5LTExZWEtOTUyMS0wMTAwMmRhMTc5NzciLCJidXNpbmVzc191dWlkIjoiYzUyYWJjNTAtYjQ5OS0xMWVhLWE0OGMtMDEwMGYxYTUwYzZl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TlRrMk1URXdOekk1ZlEuQmlkZ29CbTJ5NkZ1aXM3WTc3VVVwYndPdlJ5YkFVY2tBZ2ZWWm5KNHRFMCJ9fQ.UgLS557rCWbLxQMy_TcidK-IMymyKxMMcXSAOV3M-H8"
}

logout

Perminently revoke your refresh token.

Parameters

null

Usage

await Xedi.Auth.logout();

Events

Emits auth_deleted on successful revocation of the refresh token.

{
"method": "logout"
}

Response

null

Change Password

Update the password for a user

Parameters

PropertyTypeRequiredExample
paramsPassword{user_id: '92ac7274-9369-11ea-9521-01002da17977', password: "new-password", password_confirmation: "new-password", current_password: "old-password" }

Usage

Xedi.Auth.changePassword({ user_id: '92ac7274-9369-11ea-9521-01002da17977', password: "new-password", password_confirmation: "new-password", current_password: "old-password" });

Response

{
"_id": "92ac7274-9369-11ea-9521-01002da17977",
"email": "t.stark@avengers.org",
"first_name": "Anthony",
"last_name": "Stark",
"job_title": "Iron Man",
"contact_no": "(970) 517-1743 x67916",
"avatar": "https://assets.avengers.org/images/iron_man.png",
"created_at": "2020-05-11 10:27:03",
"updated_at": "2020-05-11 10:30:14",
"is_active": 1
}
}

Change Email

Update the Email for a user

Parameters

PropertyTypeRequiredExample
userUuidString"92ac7274-9369-11ea-9521-01002da17977"
emailStringsome_new@email.com

Usage

Xedi.Auth.changeEmail('92ac7274-9369-11ea-9521-01002da17977', 'some_new@email.com');

Response

{
"data": []
}