Third Party Login
After applying for an API key, you will be able to retrieve the user’s data through Berify third party login. For testing, please insert "https://sandbox-staging-app.berify.io" into the {domain} section of the URL.
Demo
Step 1 : Apply for an API Key
After obtaining the API key, place the obtained apiKeyId into https://sandbox-staging-app.berify.io/berify/thirdParty?apiKeyId={apiKeyId}. Through this link, you can access the third party login page. You will receive a token upon completing the login process.
Example:
- Next.js
export default function Home() {
const router = useRouter();
return (
<div style={{ height: '100vh', display: 'flex', flexDirection: 'column', justifyContent: 'center', textAlign: 'center' }}>
<h1>
Go to third-party login
</h1>
<div style={{marginTop:'4rem'}}>
<button style={{ fontSize: '16px', background: '#9c25ff', color: '#ffffff', border:0, padding: '8px 32px', borderRadius:'4px', cursor: 'pointer'}}
onClick={async () => {
router.push('https://sandbox-staging-app.berify.io/berify/thirdParty?apiKeyId={apiKeyId}');
}}>
Log in
</button>
</div>
</div>
)
}
Response:
- token: string
- error: string
{
"token": "2qgl7y5xoqgtg0v59ei0hkgnq4x0nrdgqllu5r2j8arwy8mfiykho7qo6q3nly4n",
"error": ""
}
Step 2 : Delete Token and Retrieve User Data
DELETE /auth/token/{tokenId}
Deletes token and retrieves user data.
Request parameters:
- tokenId: string
Request:
- secret : string
Example:
- Next.js
import { NextApiRequest, NextApiResponse } from 'next';
import BerifyAppApi from '@bytexbyte/berify-app-open-api';
// Initialize the API client with your credentials
const berifyAppApi = new BerifyAppApi({
host: 'YOUR_DOMAIN _NAME', // (For testing, please use https://sandbox-staging-app.berify.io)
env: '/path/to/your/environment', // Specify your environment if needed
secretKey: 'App-Berify-Secret', // Do not modify
secret: 'YOUR_SECRET_HERE' // This is the secret key provided by Berify
});
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
switch (req.method) {
case 'GET': {
const { token } = req.query;
if (typeof tokenId === 'string') {
const deletedTokenUserData = await berifyAppApi.auth.deleteToken({ token: tokenId });
console.log('get user data:', deletedTokenUserData);
}
return res.redirect('http://localhost:3000');
}
default: {
res.setHeader('Allow', ['GET']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
}
Response:
- user:
- id: string
- email: string
- phone: string
{
"user": {
"id": "a49f49b8-8036-4ff4-ae84-2c955a60b952",
"email": "test@gmail.com",
"phone": "+1-582***743",
}
}
HTTP status code summary:
200(OK) - Everything worked as expected.401(Unauthorized) - Invalid or missing access token.405(Method Not Allowed) - Unacceptable HTTP method for requested resource.
Step 3 : Get a session
GET /auth/session
Returns a client-safe session object - or an empty object if there is no session.
Example:
- Next.js
https://{domain}/api/auth/session
Response:
- expires: Date
- user:
- id: string
- images: string
- email: string
- phone: string
- firstName: string
- lastName: string
- isTester: boolean
- isPasswordLogin: boolean
{
"expires": "2024-03-07T09:40:29.501Z",
"user": {
"id": "a49f49b8-8036-4ff4-ae84-2c955a60b952",
"images": "https://textimage.image.com",
"email": "test@gmail.com",
"phone": "+1-582***743",
"firstName": "Myles",
"lastName": "Drake",
"isTester": true,
"isPasswordLogin": true
}
}