tencent cloud

Feedback

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

    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 avaliable.

    7x24 Phone Support