-
Notifications
You must be signed in to change notification settings - Fork 462
Feature/additional parameters #33
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |
| import com.facebook.react.bridge.ReactMethod; | ||
| import com.facebook.react.bridge.Promise; | ||
| import com.facebook.react.bridge.ReadableArray; | ||
| import com.facebook.react.bridge.ReadableMap; | ||
| import com.facebook.react.bridge.ReadableMapKeySetIterator; | ||
| import com.facebook.react.bridge.WritableMap; | ||
|
|
||
| import net.openid.appauth.AuthorizationException; | ||
|
|
@@ -26,6 +28,7 @@ | |
|
|
||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
|
|
||
| public class RNAppAuthModule extends ReactContextBaseJavaModule implements ActivityEventListener { | ||
|
|
||
|
|
@@ -63,8 +66,29 @@ private WritableMap tokenResponseToMap(TokenResponse response) { | |
| return map; | ||
| } | ||
|
|
||
| private HashMap<String, String> additionalParametersToMap(ReadableMap additionalParameters) { | ||
|
|
||
| HashMap<String, String> additionalParametersHash = new HashMap<>(); | ||
|
|
||
| ReadableMapKeySetIterator iterator = additionalParameters.keySetIterator(); | ||
|
|
||
| if (iterator.hasNextKey()) { | ||
|
||
| String nextKey = iterator.nextKey(); | ||
| additionalParametersHash.put(nextKey, additionalParameters.getString(nextKey)); | ||
| } | ||
|
|
||
| return additionalParametersHash; | ||
| } | ||
|
|
||
| @ReactMethod | ||
| public void authorize(String issuer, final String redirectUrl, final String clientId, final ReadableArray scopes, final Promise promise) { | ||
| public void authorize( | ||
| String issuer, | ||
| final String redirectUrl, | ||
| final String clientId, | ||
| final ReadableArray scopes, | ||
| final ReadableMap additionalParameters, | ||
| final Promise promise | ||
| ) { | ||
|
|
||
| final Context context = this.reactContext; | ||
| this.promise = promise; | ||
|
|
@@ -88,11 +112,16 @@ public void onFetchConfigurationCompleted( | |
| serviceConfiguration, | ||
| clientId, | ||
| ResponseTypeValues.CODE, | ||
| Uri.parse(redirectUrl)); | ||
| Uri.parse(redirectUrl) | ||
| ) | ||
| .setScope(scopesString); | ||
|
|
||
| if (additionalParameters != null) { | ||
| authRequestBuilder.setAdditionalParameters(additionalParametersToMap(additionalParameters)); | ||
| } | ||
|
|
||
| AuthorizationRequest authRequest = authRequestBuilder.build(); | ||
|
|
||
| AuthorizationRequest authRequest = authRequestBuilder | ||
| .setScope(scopesString) | ||
| .build(); | ||
| AuthorizationService authService = new AuthorizationService(context); | ||
| Intent authIntent = authService.getAuthorizationRequestIntent(authRequest); | ||
| currentActivity.startActivityForResult(authIntent, 0); | ||
|
|
@@ -103,7 +132,15 @@ public void onFetchConfigurationCompleted( | |
| } | ||
|
|
||
| @ReactMethod | ||
| public void refresh(String issuer, final String redirectUrl, final String clientId, final String refreshToken, final ReadableArray scopes, final Promise promise) { | ||
| public void refresh( | ||
| String issuer, | ||
| final String redirectUrl, | ||
| final String clientId, | ||
| final String refreshToken, | ||
| final ReadableArray scopes, | ||
| final ReadableMap additionalParameters, | ||
| final Promise promise | ||
| ) { | ||
| final Context context = this.reactContext; | ||
|
|
||
| final String scopesString = this.arrayToString(scopes); | ||
|
|
@@ -123,13 +160,17 @@ public void onFetchConfigurationCompleted( | |
| new TokenRequest.Builder( | ||
| serviceConfiguration, | ||
| clientId | ||
| ); | ||
| ) | ||
| .setScope(scopesString) | ||
| .setRefreshToken(refreshToken) | ||
| .setRedirectUri(Uri.parse(redirectUrl)); | ||
|
|
||
| if (additionalParameters != null) { | ||
| tokenRequestBuilder.setAdditionalParameters(additionalParametersToMap(additionalParameters)); | ||
| } | ||
|
|
||
| TokenRequest tokenRequest = tokenRequestBuilder.build(); | ||
|
|
||
| TokenRequest tokenRequest = tokenRequestBuilder | ||
| .setScope(scopesString) | ||
| .setRefreshToken(refreshToken) | ||
| .setRedirectUri(Uri.parse(redirectUrl)) | ||
| .build(); | ||
|
|
||
| AuthorizationService authService = new AuthorizationService(context); | ||
|
|
||
|
|
||
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
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
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
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 |
|---|---|---|
|
|
@@ -4076,7 +4076,7 @@ preserve@^0.2.0: | |
| version "0.2.0" | ||
| resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" | ||
|
|
||
| prettier@^1.10.2: | ||
| [email protected]: | ||
| version "1.10.2" | ||
| resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.10.2.tgz#1af8356d1842276a99a5b5529c82dd9e9ad3cc93" | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpful to document how these additional parameters are passed in the request or is that obvious to anyone who is using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Essentially
would be sent as
But I'll make it more explicit in the docs.