Sign up with Oauth
In this example, we demonstrate how to sign up with Oauth.
✅ Purpose of the scenario:
- The user registers with an OAuth provider (Google, Facebook, etc.)
- Authenticate the user with the OAuth authorization code
- Retrieve authenticated user data after a successful OAuth flow
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- OAuth provider credentials (client_id and client_secret) from Google, Facebook, or another provider.
- Authorization code obtained from the OAuth provider redirect.
- Configured redirect_uri that matches the one registered with the OAuth provider.
📌 Important:
- These examples do not include error handling.
- You can manage errors using a try-catch block or by employing a construction like await Promise.catch((error) => error).
- Ensure that the formIdentifier used in the updateUser() method matches the one configured in your OneEntry project.
Scenario
1. Import defineOneEntry from SDK and define url and token
Example:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Creating an API client with defineOneEntry() function
Example:
const { AuthProvider, Users } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. User registration with AuthProvider.oauthSignUp()
Data:
{
"client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com",
"client_secret": "43434343434",
"code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g",
"grant_type": "registration",
"redirect_uri": "http://localhost:3000",
"formData": {
"en_US": [
null
]
}
}
Example:
const signUpResponse = await AuthProvider.oauthSignUp('email', body).catch((e) => e);
Result:
{
"statusCode": 403,
"timestamp": "2026-01-04T01:20:52.612Z",
"message": "Permission data not found. Provide the permission for requested url",
"pageData": null
}
4. User authentication with AuthProvider.oauthSignUp()
Data:
{
"client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com",
"client_secret": "43434343434",
"code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g",
"grant_type": "authorization_code",
"redirect_uri": "http://localhost:3000",
"formData": {
"en_US": [
null
]
}
}
Example:
const authResponse = await AuthProvider.oauthSignUp('email', authBody).catch((e) => e);
Result:
{
"statusCode": 403,
"timestamp": "2026-01-04T01:20:52.792Z",
"message": "Permission data not found. Provide the permission for requested url",
"pageData": null
}
5. Now you can get user data with Users.getUser()
Example:
const userData = await Users.getUser();
Final example
// 1. Import defineOneEntry from SDK define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
// 2. Creating an API client:
const { AuthProvider, Users } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. User registration with AuthProvider.oauthSignUp()
const body = {
"client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com",
"client_secret": "43434343434",
"code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g",
"grant_type": "registration",
"redirect_uri": "http://localhost:3000"
};
const signUpResponse = await AuthProvider.oauthSignUp('email', body).catch((e) => e);
// console.log(JSON.stringify(signUpResponse));
// 4. User authentication with AuthProvider.oauthSignUp()
const authBody = {
"client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com",
"client_secret": "43434343434",
"code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g",
"grant_type": "authorization_code",
"redirect_uri": "http://localhost:3000"
};
const authResponse = await AuthProvider.oauthSignUp('email', authBody).catch((e) => e);
// console.log(JSON.stringify(authResponse));
// 5. Now you can get user data with Users.getUser()
const user = await Users.getUser().catch((e) => e);
// console.log(JSON.stringify(user));