Skip to content

Conversation

@ashfaq3112
Copy link

Summary:

Instagram has deprecated its standalone OAuth API, which breaks the login and logout flows for the instagram provider in hello.js. As a result:

Login always returns "cancelled" or closes the popup unexpectedly.

Logout always fails with 405 Method Not Allowed or CSP/CORS blocking.

Since Instagram no longer supports its legacy OAuth endpoints, client-side login cannot be restored.
However, logout can be improved to avoid errors and maintain a clean local session.

This PR updates the Instagram provider to use a modernized logout approach and documents Instagram’s API deprecation.

Fixes Included
🔹 1. New logout handler using POST + CSRF

The old GET request to /accounts/logout/ is no longer supported.

This PR:

Switches to POST https://www.instagram.com/accounts/logout/

Extracts CSRF token automatically from cookies (csrftoken or csrfmiddlewaretoken)

Sends credentials: "include" so Instagram session cookies are forwarded

Handles CORS failures gracefully (Instagram now blocks all cross-site logout)

Always clears the local HelloJS session and resolves the callback

🔹 2. Safe fallback for CORS-blocked responses

Even though Instagram blocks the response, hello.js still:

Clears local session

Fires the auth.logout event

Prevents unhandled exceptions

🔹 3. Documentation update

Added notes explaining that:

Instagram’s standalone OAuth API has been deprecated

Login cannot function fully on client-side JS

Full authentication now requires Facebook Graph API / Instagram Basic Display API

Notes

Instagram’s current authentication flow cannot work fully client-side because:

Old OAuth endpoints have been removed

/accounts/logout/ requires POST + CSRF

Instagram does not provide CORS headers

OAuth must be completed server-side using Facebook Graph API

This PR ensures hello.js handles the logout more gracefully and informs developers about the required migration path.

Code Changes
Updated Logout Function
logout: function (callback, p) {

// Extract CSRF token from Instagram cookie
function getCSRFCookie() {
    try {
        const cookie = (document.cookie || '')
            .split('; ')
            .find(c => c.startsWith('csrftoken=') || c.startsWith('csrfmiddlewaretoken='));
        return cookie ? cookie.split('=')[1] : null;
    } catch (e) {
        return null;
    }
}

const csrf = getCSRFCookie();

const opts = {
    method: "POST",
    credentials: "include",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    body: ""
};

if (csrf) {
    opts.headers["X-CSRFToken"] = csrf;
}

// Attempt logout — will be CORS blocked but still hits server
fetch("https://www.instagram.com/accounts/logout/", opts)
    .catch(() => { /* CORS blocked – expected */ })
    .finally(() => {
        callback({
            force: null,
            message: "Instagram logout attempted (CORS blocks response)"
        });
    });

return;

},

How to Test

1.Build the repo:

npm install
npm run build

2.Use the test page:

hello('instagram').logout({ force: true })
.then(r => console.log("LOGOUT:", r));

3.Expected Behavior:

->No uncaught errors

->auth.logout event is triggered

->Local session removed

->Network tab shows a POST to /accounts/logout/

->Response is blocked by CORS (normal)

Final Notes

This PR does not attempt to restore Instagram login (which is impossible on the client due to API deprecation). Instead, it:

✔ Fixes the logout errors
✔ Ensures consistent behavior
✔ Removes confusing CSP/CORS failures
✔ Updates documentation to reflect Instagram’s API changes

This improves developer experience and avoids false expectations.

@MrSwitch MrSwitch force-pushed the master branch 3 times, most recently from dc9b406 to f6f63dd Compare January 4, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant