2012-07-06 32 views
3

我正在制作一个表单,允许用户在将请求合并到项目核心之前同意某些条件。为了提供GitHub帐户的所有权证明,用户需要使用GitHub API为我的网站提供对其GitHub帐户的只读访问权限。GitHub API3删除访问令牌

我想向用户提供“撤销访问”功能 - 我实际上并不想访问他们的账户,这只是验证账户所有权的好方法。

我知道用户可以通过GitHub Applications设置页面撤消应用程序访问权限,但我希望在可能的情况下简化此操作。我已经浏览了GitHub APIv3文档,但没有看到任何允许请求GitHub撤消access_token的任何内容。

问题

是否有可能以编程方式撤销我的应用程序的access_token?

回答

2

如果你看一下GitHub OAuth Authorizations API,他们列出删除使用“删除/授权/:id为”授权的能力

+0

谢谢@ mark-s,我确实看到了。我应该使用什么:id? – 2012-07-15 20:59:03

+0

当您执行“GET /授权”时,每个授权都有一个与其关联的ID。这就是你使用的:ID – 2012-07-15 23:18:56

+0

我无法撤销授权,请你帮我解决它。 。 – 2013-12-09 10:33:21

0

我知道这是晚了,但我希望这会帮助别人,

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.github.com/applications/%@/tokens/%@",GITHUB_CLIENT_ID,token]]; 

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
    NSString *theUsername = GITHUB_CLIENT_ID; 
    NSString *thePassword = GITHUB_CLIENT_SECRET; 

    [request addValue:[NSString stringWithFormat:@"Basic %@",[self base64forData:[[NSString stringWithFormat:@"%@:%@",theUsername,thePassword] dataUsingEncoding: NSUTF8StringEncoding]]] forHTTPHeaderField:@"Authorization"]; 
    [request setHTTPMethod:@"DELETE"]; 
    [request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 

    NSError *error = nil; 
    NSURLResponse *response; 

    [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 



- (NSString*)base64forData:(NSData*)theData 
{ 
    const uint8_t* input = (const uint8_t*)[theData bytes]; 
    NSInteger length = [theData length]; 

    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/="; 

    NSMutableData* data = [NSMutableData dataWithLength:((length + 2)/3) * 4]; 
    uint8_t* output = (uint8_t*)data.mutableBytes; 

    NSInteger i; 
    for (i=0; i < length; i += 3) { 
     NSInteger value = 0; 
     NSInteger j; 
     for (j = i; j < (i + 3); j++) { 
      value <<= 8; 

      if (j < length) { 
       value |= (0xFF & input[j]); 
      } 
     } 

     NSInteger theIndex = (i/3) * 4; 
     output[theIndex + 0] =     table[(value >> 18) & 0x3F]; 
     output[theIndex + 1] =     table[(value >> 12) & 0x3F]; 
     output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '='; 
     output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '='; 
    } 

    return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]; 
} 
1

可以撤销的身份验证令牌:

撤销授权的应用程序

OAuth应用程序所有者还可以撤销OAuth 应用程序的单个令牌。您必须对此方法使用基本身份验证,其中 用户名是OAuth应用程序client_id,密码是 其client_secret。

DELETE /应用/:CLIENT_ID /令牌/:

的access_token

documentation是正确的;我已经验证了这个作品。