+ Start a Discussion
c_r_carvalhoc_r_carvalho 

OAuthToken revoke access token

Hi Guys,

Well I developed the following code:
 
List< OauthToken > lstOauthToken = [Select id, user.name, accesstoken From OauthToken Where userid =: Userinfo.getUserId() AND 
        	(appname = 'Salesforce1 for Android' OR appname = 'Salesforce1 for iOS')];
        system.debug('CR=lstOauthToken=size= '+lstOauthToken.size());
        system.debug('CR=lstOauthToken=accesstoken= '+lstOauthToken[0].accesstoken);
        String urlRevoke = 'https://login.salesforce.com/services/oauth2/revoke?token=';
        urlRevoke += lstOauthToken[0].accesstoken;
        system.debug('CR=urlRevoke= '+urlRevoke);
        HttpRequest req = new HttpRequest();
        req.setEndpoint(urlRevoke);
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setMethod('GET');
        
        Http http = new Http();
        HttpResponse res = http.send(req);
        system.debug('CR=response= '+res);

However when I get the access code to revoke it I got this debug, look:

Endpoint=https://login.salesforce.com/services/oauth2/revoke?token=(hidden)
I don't know why I cannot to see this code.
Because of that I got this error message: System.HttpResponse[Status=Bad Request, StatusCode=400]

Anybody can help me?
c_r_carvalhoc_r_carvalho
Hi guysm

I foud the correct parameter. It is "DeleteToken" field.
But now I am getting:

Status=Found, StatusCode=302

If someone know how to fix, share please!
AAjayAAjay
I got same proble...

Status=Found, StatusCode=302

​Anybody can help me? 
ThukkaramThukkaram
Encoding of deletetoken is missing above. thanks!

List< OauthToken > lstOauthToken = [select Id, AccessToken, UserId, user.name, RequestToken, CreatedDate, AppName, LastUsedDate, UseCount, DeleteToken, AppMenuItemId from OauthToken where UserId ='<USR ID>' and AppName ='<APP NAME>'];
        String urlRevoke = 'https://test.salesforce.com/services/oauth2/revoke?token=';
        urlRevoke += EncodingUtil.URLENCODE(lstOauthToken[0].DeleteToken,'UTF-8');
          system.debug('@TK revoke '+urlRevoke);
        HttpRequest req = new HttpRequest();
        req.setEndpoint(urlRevoke);
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setMethod('GET');
        Http http = new Http();
        HttpResponse res = http.send(req);
        system.debug('@TK response '+res);