13
13
import com .facebook .react .bridge .ReactMethod ;
14
14
import com .facebook .react .bridge .Promise ;
15
15
import com .facebook .react .bridge .ReadableArray ;
16
+ import com .facebook .react .bridge .ReadableMap ;
17
+ import com .facebook .react .bridge .ReadableMapKeySetIterator ;
16
18
import com .facebook .react .bridge .WritableMap ;
17
19
18
20
import net .openid .appauth .AuthorizationException ;
26
28
27
29
import java .text .SimpleDateFormat ;
28
30
import java .util .Date ;
31
+ import java .util .HashMap ;
29
32
30
33
public class RNAppAuthModule extends ReactContextBaseJavaModule implements ActivityEventListener {
31
34
@@ -63,8 +66,29 @@ private WritableMap tokenResponseToMap(TokenResponse response) {
63
66
return map ;
64
67
}
65
68
69
+ private HashMap <String , String > additionalParametersToMap (ReadableMap additionalParameters ) {
70
+
71
+ HashMap <String , String > additionalParametersHash = new HashMap <>();
72
+
73
+ ReadableMapKeySetIterator iterator = additionalParameters .keySetIterator ();
74
+
75
+ if (iterator .hasNextKey ()) {
76
+ String nextKey = iterator .nextKey ();
77
+ additionalParametersHash .put (nextKey , additionalParameters .getString (nextKey ));
78
+ }
79
+
80
+ return additionalParametersHash ;
81
+ }
82
+
66
83
@ ReactMethod
67
- public void authorize (String issuer , final String redirectUrl , final String clientId , final ReadableArray scopes , final Promise promise ) {
84
+ public void authorize (
85
+ String issuer ,
86
+ final String redirectUrl ,
87
+ final String clientId ,
88
+ final ReadableArray scopes ,
89
+ final ReadableMap additionalParameters ,
90
+ final Promise promise
91
+ ) {
68
92
69
93
final Context context = this .reactContext ;
70
94
this .promise = promise ;
@@ -88,11 +112,16 @@ public void onFetchConfigurationCompleted(
88
112
serviceConfiguration ,
89
113
clientId ,
90
114
ResponseTypeValues .CODE ,
91
- Uri .parse (redirectUrl ));
115
+ Uri .parse (redirectUrl )
116
+ )
117
+ .setScope (scopesString );
118
+
119
+ if (additionalParameters != null ) {
120
+ authRequestBuilder .setAdditionalParameters (additionalParametersToMap (additionalParameters ));
121
+ }
122
+
123
+ AuthorizationRequest authRequest = authRequestBuilder .build ();
92
124
93
- AuthorizationRequest authRequest = authRequestBuilder
94
- .setScope (scopesString )
95
- .build ();
96
125
AuthorizationService authService = new AuthorizationService (context );
97
126
Intent authIntent = authService .getAuthorizationRequestIntent (authRequest );
98
127
currentActivity .startActivityForResult (authIntent , 0 );
@@ -103,7 +132,15 @@ public void onFetchConfigurationCompleted(
103
132
}
104
133
105
134
@ ReactMethod
106
- public void refresh (String issuer , final String redirectUrl , final String clientId , final String refreshToken , final ReadableArray scopes , final Promise promise ) {
135
+ public void refresh (
136
+ String issuer ,
137
+ final String redirectUrl ,
138
+ final String clientId ,
139
+ final String refreshToken ,
140
+ final ReadableArray scopes ,
141
+ final ReadableMap additionalParameters ,
142
+ final Promise promise
143
+ ) {
107
144
final Context context = this .reactContext ;
108
145
109
146
final String scopesString = this .arrayToString (scopes );
@@ -123,13 +160,17 @@ public void onFetchConfigurationCompleted(
123
160
new TokenRequest .Builder (
124
161
serviceConfiguration ,
125
162
clientId
126
- );
163
+ )
164
+ .setScope (scopesString )
165
+ .setRefreshToken (refreshToken )
166
+ .setRedirectUri (Uri .parse (redirectUrl ));
167
+
168
+ if (additionalParameters != null ) {
169
+ tokenRequestBuilder .setAdditionalParameters (additionalParametersToMap (additionalParameters ));
170
+ }
171
+
172
+ TokenRequest tokenRequest = tokenRequestBuilder .build ();
127
173
128
- TokenRequest tokenRequest = tokenRequestBuilder
129
- .setScope (scopesString )
130
- .setRefreshToken (refreshToken )
131
- .setRedirectUri (Uri .parse (redirectUrl ))
132
- .build ();
133
174
134
175
AuthorizationService authService = new AuthorizationService (context );
135
176
0 commit comments