Contents
Overview
- Authify is a RESTful API that supports secure user authentication via email and Google-based methods. Users can sign up with an email, generating a unique JWT token, and sign in using either email or Google authentication. The API also enables fetching user details from the JWT token.
- The API offers features such as password reset through OTP sent to the registered email and supports account deletion. Additionally, it includes two-factor authentication to enhance security.
- Authify provides real-time email notifications for all account activities, such as login events, password modifications, and other relevant actions, ensuring users are promptly informed of any changes to their accounts.
Endpoints
Signup
I Sending OTP to given email address:
POST https://api-authify.azurewebsites.net/auth/signup/email
Body :
Parameter | Type | Description |
---|---|---|
email | string | Required Email Address |
Usage
javascript:
const createNewUserViaEmail = await fetch('https://api-authify.azurewebsites.net/signup/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: credentials.email})
});
const json = await createNewUserViaEmail.json();
console.log(json);
Response
{ "success": true,}
II Verivication and creation of a new user:
POST https://api-authify.azurewebsites.net/auth/signup/email/verify
Body :
Parameter | Type | Description |
---|---|---|
name | string | Required Name (min length : 3) |
email | string | Required Email add |
password | string | Required password (min length : 8) |
authcode | number | Required password (length : 6) |
Usage
javascript:
const createNewUser = await fetch(
"https://api-authify.azurewebsites.net/auth/signup",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: credentials.name,
email: credentials.email,
password: credentials.password,
authcode: credentials.authCode
}),
}
);
const response = await createNewUser.json();
console.log(json);
Response
{
"success": true,
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXIiOiI2MjljN2YzYWVmMzEwNjg4N2EyYWNkZDAifSwiaWF0IjoxNjU0NDIzMzU1fQ.R1rX4sRHv-o3gDWT3XqtobYEKeYRmyvA8ZLpveobuGc"
}
Signin
POST https://api-authify.azurewebsites.net/auth/signin
Body :
Parameter | Type | Description |
---|---|---|
email | string | Required Email address |
password | string | Required password (min length : 8) |
Usage
javascript:
const signInUser = await fetch(
"https://api-authify.azurewebsites.net/auth/signin",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: credentials.email,
password: credentials.password,
}),
}
);
const response = await signInUser.json();
console.log(json);
Response
{
"success": true,
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXIiOiI2MjljN2YzYWVmMzEwNjg4N2EyYWNkZDAifSwiaWF0IjoxNjU0NDIzMzU1fQ.R1rX4sRHv-o3gDWT3XqtobYEKeYRmyvA8ZLpveobuGc"
}
Verification
POST https://api-authify.azurewebsites.net/auth/verifyuser
Header :
Parameter | Type | Description |
---|---|---|
Content-Type | string | Required application/json |
auth-token | string | Required eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1..... |
Usage
javascript:
const getUser = await fetch(
"https://api-authify.azurewebsites.net/auth/verifyuser",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"auth-token":
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXIiOiI2MjljN2YzYWVmMzEwNjg4N2EyYWNkZDAifSwiaWF0IjoxNjU0NDIzMzU1fQ.R1rX4sRHv-o3gDWT3XqtobYEKeYRmyvA8ZLpveobuGc",
},
}
);
const response = await getUser.json();
console.log(json);
Response
{
"_id": "629c7f3aef3106887a2acdd0",
"name": "user",
"email": "userEmail@fudnef.com",
"googleId": null,
"date": "2022-06-05T10:02:34.938Z",
"__v": 0
}
Reseting password
Can be used for both resetting the password and updation of password
I : Sending OTP to corresponding Email address
POST https://api-authify.azurewebsites.net/fogotpassword
Body :
Parameter | Type | Description |
---|---|---|
email | string | Required. Email address |
Usage
javascript:
const sendMail = await fetch(
"https://api-authify.azurewebsites.net/fogotpassword",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email: credentials.email }),
}
);
const response = await sendMail.json();
console.log(response);
Response
{
"success": true,
"message": "Email Send"
}
II : OTP verification and updating new password
POST https://api-authify.azurewebsites.net/fogotpassword/verify
Body :
Parameter | Type | Description |
---|---|---|
email | string | Required. Email address |
authcode | number | Required. OTP (6 digit) |
password | string | Required. new password (min length : 8) |
Usage
javascript:
const changePassword = await fetch(
"https://api-authify.azurewebsites.net/fogotpassword/verify",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: credentials.email,
authcode: Number(credentials.OTP),
password: credentials.password,
}),
}
);
const response = await changePassword.json();
Response
{
"success" : true ,
"msg" : "Password Updated"
}
Authentication with Google
To authenticate with google, you need to pass your app url as a query parameter in the url. Once the user authenticates with google, the user will be redirected to the app url with the auth token as a query parameter. You can fetch the token from the url and use it for further authentication.
PUT https://api-authify.azurewebsites.net/auth/google?url={YOUR_APP_URL}
Usage
html:
<!-- Redirection to Oauth screen and trigger initialization -->
<a href='https://api-authify.azurewebsites.net/auth/google?url={YOUR_APP_URL}' target='_blank'>Continue with Google </a>
Response URL
https://www.mrdhruv.co/?authToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXIiOiI2NjFlODljYmJlNjgzMzc1N2FiNTUxY2YifSwiaWF0IjoxNzEzMjc3NDUyfQ.n8_WjYngosSCByfeQgtyx51hVle6p1eRY6QcdZojOSs
Delete Account
I Sending Otp to given email address:
POST https://api-authify.azurewebsites.net/auth/delete/email
Body :
Parameter | Type | Description |
---|---|---|
email | string | Required Email address |
Usage
javascript:
const deleteGen = await fetch('https://api-authify.azurewebsites.net/autdelete/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: user.email })
})
const response = await deleteGen.json();
console.log(response)
Response
{ "success": true,}
II OTP verification and account deletion:
POST https://api-authify.azurewebsites.net/auth/delete/email
Body :
Parameter | Type | Description |
---|---|---|
email | string | Required Email address |
authcode | number | Required OTP (6 digit) |
password | string | Required Password (min-length : 8) |
Usage
javascript:
const response = await fetch('https://api-authify.azurewebsites.net/auth/delete/email/verify', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: user.email, authcode: Number(credentials. verifyToken), password: credentials.password })
})
const response = await deleteGen.json();
console.log(response)
Response
{ "success": true,}