tencent cloud

All product documents
Tencent Cloud EdgeOne
Remote Authentication
Last updated: 2023-10-30 17:46:16
Remote Authentication
Last updated: 2023-10-30 17:46:16
In order to avoid customers' resources being accessed by illegal users, this example transmits the request to the customer-specified remote authentication server. The authentication server verifies the user's request, and the Edge functions decide whether to allow access to the target resources based on the check result returned by the remote authentication server. If the authentication fails, the client will be responded with a 403 status code.
async function handleRequest(request) {
// Remote authentication API address
const checkAuthUrl = 'https://www.example.com/';
// Initiate remote authentication
const checkAuthRes = await fetch(checkAuthUrl);

// Authentication passed, normal access to resources
if (checkAuthRes.status === 200) {
return fetch(request, {
headers: request.headers,
});
}
// Authentication failed, prohibit access to resources
return new Response(null, {
status: 403
});
}

addEventListener('fetch', e => {
e.respondWith(handleRequest(e.request));
});

Example preview

Enter the URL that matches the triggering rules of the Edge functions in the address bar of the browser on both PC and mobile (e.g., https://example.com/app/index.html) to preview the example effect.
Authentication passed, normal access to resources.



Authentication failed, prohibit access to resources.




Related references

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon