Swapnil Luktuke
Swapnil Luktuke

Reputation: 10475

Programmatically logout OAuth Connector in Drupal 7

I am using OAuth Connector module to authenticate a user from an external source. Each user on the external source has a corresponding Drupal user account.

After successful oath authentication, user is programmatically logged in with a matching Drupal user account using user_authenticate and user_login_finalize.

When the drupal user logs out, I want to revoke OAuth access programmatically in user_logout. But I could not find any logout/revoke/destroy/invalidate method in any of the OAuth classes.

What is the correct way to programmatically logout an authenticated OAuth user in Drupal 7?

P.S. I know the system i have mentioned above is very inconvenient and there are many better ways to share user accounts between sites but my question is limited to 'how to logout in Drupal 7 OAuth connector module'.

EDIT: If I clear the saved OAuth tokens is it similar to logging out? Can anyone shed more light on what all data is stored by OAuth module and how to clear it if there is no direct logout option?

Upvotes: 8

Views: 674

Answers (1)

Propaganistas
Propaganistas

Reputation: 1792

If I understand your question correctly, you can just call user_logout() to programmatically logout an authenticated user.

This is possible because the Connector module (upon which OAuth Connector is based) incorporates hook_user_logout() to propagate the logout call to the OAuth provider.

Hopefully this answers your question?

Note: is there a specific reason why you aren't using the more popular (and stable) OAuth module?

Upvotes: 3

Related Questions