Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.7k
Support for OAuth with Apple accounts using ScribeJava#1074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
meraedit wants to merge1 commit intoscribejava:masterChoose a base branch fromServoy:appleid
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsREADME.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletionsscribejava-apis/src/main/java/com/github/scribejava/apis/apple/AppleIDApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.github.scribejava.apis.apple; | ||
import java.io.OutputStream; | ||
import com.github.scribejava.core.builder.api.DefaultApi20; | ||
import com.github.scribejava.core.httpclient.HttpClient; | ||
import com.github.scribejava.core.httpclient.HttpClientConfig; | ||
import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; | ||
import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; | ||
public class AppleIDApi extends DefaultApi20 | ||
{ | ||
protected AppleIDApi() | ||
{ | ||
} | ||
private static class InstanceHolder | ||
{ | ||
private static final AppleIDApi INSTANCE = new AppleIDApi(); | ||
} | ||
public static AppleIDApi instance() | ||
{ | ||
return InstanceHolder.INSTANCE; | ||
} | ||
@Override | ||
public String getAccessTokenEndpoint() | ||
{ | ||
return "https://appleid.apple.com/auth/token"; | ||
} | ||
@Override | ||
protected String getAuthorizationBaseUrl() | ||
{ | ||
return "https://appleid.apple.com/auth/authorize"; | ||
} | ||
@Override | ||
public String getRevokeTokenEndpoint() | ||
{ | ||
return "https://appleid.apple.com/auth/revoke"; | ||
} | ||
@Override | ||
public ClientAuthentication getClientAuthentication() | ||
{ | ||
return RequestBodyAuthenticationScheme.instance(); | ||
} | ||
@Override | ||
public AppleIDService createService(String apiKey, String apiSecret, String callback, String defaultScope, | ||
String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, | ||
HttpClient httpClient) | ||
{ | ||
return new AppleIDService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, | ||
userAgent, httpClientConfig, httpClient); | ||
} | ||
} |
27 changes: 27 additions & 0 deletionsscribejava-apis/src/main/java/com/github/scribejava/apis/apple/AppleIDService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.scribejava.apis.apple; | ||
import java.io.OutputStream; | ||
import com.github.scribejava.core.builder.api.DefaultApi20; | ||
import com.github.scribejava.core.httpclient.HttpClient; | ||
import com.github.scribejava.core.httpclient.HttpClientConfig; | ||
import com.github.scribejava.core.model.OAuthRequest; | ||
import com.github.scribejava.core.oauth.AccessTokenRequestParams; | ||
import com.github.scribejava.core.oauth.OAuth20Service; | ||
public class AppleIDService extends OAuth20Service | ||
{ | ||
public AppleIDService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, | ||
OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) | ||
{ | ||
super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); | ||
} | ||
@Override | ||
protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) | ||
{ | ||
OAuthRequest req = super.createAccessTokenRequest(params); | ||
req.addHeader("Content-Type", "application/x-www-form-urlencoded"); | ||
return req; | ||
} | ||
} |
72 changes: 72 additions & 0 deletionsscribejava-apis/src/test/java/com/github/scribejava/apis/examples/AppleIDExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.github.scribejava.apis.examples; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.Scanner; | ||
import com.github.scribejava.apis.apple.AppleIDApi; | ||
import com.github.scribejava.core.builder.ServiceBuilder; | ||
import com.github.scribejava.core.model.OAuth2AccessToken; | ||
import com.github.scribejava.core.model.OAuthConstants; | ||
import com.github.scribejava.core.oauth.OAuth20Service; | ||
public class AppleIDExample { | ||
public static void main(String[] args) throws Exception { | ||
final String apiKey = "your client id"; | ||
final String apiSecret = "your client secret"; | ||
final String secretState = "secret" + new Random().nextInt(999_999); | ||
OAuth20Service service = new ServiceBuilder(apiKey) | ||
.apiSecret(apiSecret) | ||
.callback("https://localhost/") | ||
.defaultScope("name email") | ||
.responseType("code id_token") | ||
.build(AppleIDApi.instance()); | ||
Map<String, String> additionalParams = new HashMap<>(); | ||
additionalParams.put(OAuthConstants.STATE, secretState); | ||
additionalParams.put("response_mode", "form_post"); | ||
try (Scanner in = new Scanner(System.in)) { | ||
System.out.println("Fetching the Authorication URL..."); | ||
System.out.println("Got the Authorization URL!"); | ||
final String authorizationUrl = service.getAuthorizationUrl(additionalParams); | ||
System.out.println("Now go and authorize ScribeJava here:"); | ||
System.out.println(authorizationUrl); | ||
System.out.println("And paste the authorization code here"); | ||
System.out.print(">>"); | ||
final String code = in.nextLine(); | ||
System.out.println(); | ||
System.out.println("Trading the Authorization Code for an Access Token..."); | ||
OAuth2AccessToken accessToken = service.getAccessToken(code); | ||
System.out.println("Got the Access Token!"); | ||
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); | ||
System.out.println(); | ||
System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); | ||
System.out.print(">>"); | ||
final String value = in.nextLine(); | ||
if (secretState.equals(value)) { | ||
System.out.println("State value does match!"); | ||
} else { | ||
System.out.println("Ooops, state value does not match!"); | ||
System.out.println("Expected = " + secretState); | ||
System.out.println("Got = " + value); | ||
System.out.println(); | ||
} | ||
System.out.println("Refreshing the Access Token..."); | ||
accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); | ||
System.out.println("Refreshed the Access Token!"); | ||
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); | ||
} | ||
System.out.println(); | ||
System.out.println(); | ||
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.