5

我正在制作一个表单,允许用户同意一些条件,然后才能将拉取请求合并到项目的核心中。要提供 GitHub 帐户的所有权证明,用户需要使用 GitHub API 授予我的网站对其 GitHub 帐户的只读访问权限。

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

我知道用户可以通过GitHub 应用程序设置页面撤销应用程序访问权限,但如果可能的话,我想简化这一点。我查看了 GitHub APIv3 文档,但没有看到任何允许请求 GitHub 撤销 access_token 的内容。

问题

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

4

3 回答 3

4

如果您查看GitHub OAuth Authorizations API,他们列出了使用“DELETE /authorizations/:id”删除授权的能力

于 2012-07-13T19:02:19.817 回答
4

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

撤销对应用程序的授权

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

删除 /applications/:client_id/tokens/:access_token

文件正确;我已经验证了这个作品。

于 2014-02-25T05:25:48.930 回答
1

我知道已经晚了,但我希望这对其他人有帮助,

   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[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    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];
}
于 2013-12-12T09:08:03.920 回答