Skip to content

Commit be46748

Browse files
author
Shashank Agrawal
committed
Added api for GitHub authentication.
1 parent ad55e22 commit be46748

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2011, CauseCode Technologies Pvt Ltd, India.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or
6+
* without modification, are not permitted.
7+
*/
8+
9+
package org.scribe.builder.api;
10+
11+
import org.scribe.model.OAuthConfig;
12+
import org.scribe.utils.OAuthEncoder;
13+
14+
public class GitHubApi extends DefaultApi20 {
15+
16+
private static final String AUTHORIZATION_URL = "https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s";
17+
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZATION_URL + "&scope=%s";
18+
19+
@Override
20+
public String getAccessTokenEndpoint() {
21+
return "https://github.com/login/oauth/access_token";
22+
}
23+
24+
@Override
25+
public String getAuthorizationUrl(OAuthConfig config) {
26+
if(config.hasScope()) {
27+
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()),
28+
OAuthEncoder.encode(config.getScope()));
29+
}
30+
return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)