@@ -121,23 +121,23 @@ public void simpleOperationsWithConfigurator() throws Exception {
121
121
assertThat ("incorrect environments" , oip .getEnvironments (), is (set ("myenv" )));
122
122
assertThat ("incorrect login url" , oip .getLoginURI ("foo3" , "pkce" , false , null ),
123
123
is (new URI ("https://ologin.com/oauth/authorize?" +
124
- "scope=openid" +
124
+ "scope=openid+%2Fauthenticate " +
125
125
"&state=foo3&redirect_uri=https%3A%2F%2Fologinredir.com" +
126
126
"&response_type=code&client_id=ofoo" )));
127
127
assertThat ("incorrect link url" , oip .getLoginURI ("foo4" , "pkce" , true , null ),
128
128
is (new URI ("https://ologin.com/oauth/authorize?" +
129
- "scope=openid" +
129
+ "scope=openid+%2Fauthenticate " +
130
130
"&state=foo4&redirect_uri=https%3A%2F%2Folinkredir.com" +
131
131
"&response_type=code&client_id=ofoo" )));
132
132
133
133
assertThat ("incorrect login url" , oip .getLoginURI ("foo3" , "pkce" , false , "myenv" ),
134
134
is (new URI ("https://ologin.com/oauth/authorize?" +
135
- "scope=openid" +
135
+ "scope=openid+%2Fauthenticate " +
136
136
"&state=foo3&redirect_uri=https%3A%2F%2Fmyologinred.com" +
137
137
"&response_type=code&client_id=ofoo" )));
138
138
assertThat ("incorrect link url" , oip .getLoginURI ("foo4" , "pkce" , true , "myenv" ),
139
139
is (new URI ("https://ologin.com/oauth/authorize?" +
140
- "scope=openid" +
140
+ "scope=openid+%2Fauthenticate " +
141
141
"&state=foo4&redirect_uri=https%3A%2F%2Fmyolinkred.com" +
142
142
"&response_type=code&client_id=ofoo" )));
143
143
}
@@ -150,23 +150,23 @@ public void simpleOperationsWithoutConfigurator() throws Exception {
150
150
assertThat ("incorrect environments" , oip .getEnvironments (), is (set ("myenv" )));
151
151
assertThat ("incorrect login url" , oip .getLoginURI ("foo5" , "pkce" , false , null ),
152
152
is (new URI ("https://ologin.com/oauth/authorize?" +
153
- "scope=openid" +
153
+ "scope=openid+%2Fauthenticate " +
154
154
"&state=foo5&redirect_uri=https%3A%2F%2Fologinredir.com" +
155
155
"&response_type=code&client_id=ofoo" )));
156
156
assertThat ("incorrect link url" , oip .getLoginURI ("foo6" , "pkce" , true , null ),
157
157
is (new URI ("https://ologin.com/oauth/authorize?" +
158
- "scope=openid" +
158
+ "scope=openid+%2Fauthenticate " +
159
159
"&state=foo6&redirect_uri=https%3A%2F%2Folinkredir.com" +
160
160
"&response_type=code&client_id=ofoo" )));
161
161
162
162
assertThat ("incorrect login url" , oip .getLoginURI ("foo3" , "pkce" , false , "myenv" ),
163
163
is (new URI ("https://ologin.com/oauth/authorize?" +
164
- "scope=openid" +
164
+ "scope=openid+%2Fauthenticate " +
165
165
"&state=foo3&redirect_uri=https%3A%2F%2Fmyologinred.com" +
166
166
"&response_type=code&client_id=ofoo" )));
167
167
assertThat ("incorrect link url" , oip .getLoginURI ("foo4" , "pkce" , true , "myenv" ),
168
168
is (new URI ("https://ologin.com/oauth/authorize?" +
169
- "scope=openid" +
169
+ "scope=openid+%2Fauthenticate " +
170
170
"&state=foo4&redirect_uri=https%3A%2F%2Fmyolinkred.com" +
171
171
"&response_type=code&client_id=ofoo" )));
172
172
@@ -267,15 +267,15 @@ public void returnsIllegalAuthtokenResponse() throws Exception {
267
267
final IdentityRetrievalException e =
268
268
new IdentityRetrievalException ("No access token was returned by OrcID" );
269
269
270
- setUpCallAuthToken (acode , null , redir , cliid , clisec , "name" , "fake ID" );
270
+ setUpCallAuthTokenWithJWT (acode , null , redir , cliid , clisec , "name" , "fake ID" , createJWTWithoutAmr ( "fake ID" ) );
271
271
failGetIdentities (idp , acode , "pkce" , false , e );
272
- setUpCallAuthToken (acode , "\t " , redir , cliid , clisec , "name" , "fake ID" );
272
+ setUpCallAuthTokenWithJWT (acode , "\t " , redir , cliid , clisec , "name" , "fake ID" , createJWTWithoutAmr ( "fake ID" ) );
273
273
failGetIdentities (idp , acode , "pkce" , false , e );
274
274
275
- setUpCallAuthToken (acode , "fake token" , redir , cliid , clisec , "my name" , null );
275
+ setUpCallAuthTokenWithJWT (acode , "fake token" , redir , cliid , clisec , "my name" , null , createJWTWithoutAmr ( "fake ID" ) );
276
276
failGetIdentities (idp , acode , "pkce" , false , new IdentityRetrievalException (
277
277
"No id was returned by OrcID" ));
278
- setUpCallAuthToken (acode , "fake token" , redir , cliid , clisec , "my name" , " \t \n " );
278
+ setUpCallAuthTokenWithJWT (acode , "fake token" , redir , cliid , clisec , "my name" , " \t \n " , createJWTWithoutAmr ( "fake ID" ) );
279
279
failGetIdentities (idp , acode , "pkce" , false , new IdentityRetrievalException (
280
280
"No id was returned by OrcID" ));
281
281
}
@@ -336,25 +336,25 @@ public void returnsBadResponseIdentity() throws Exception {
336
336
final String authtoken = "bartoken" ;
337
337
final String orcID = "0000-0001-1234-5678" ;
338
338
339
- setUpCallAuthToken (authCode , authtoken , redir , cliid , clisec , "my name" , orcID );
339
+ setUpCallAuthTokenWithJWT (authCode , authtoken , redir , cliid , clisec , "my name" , orcID , createJWTWithoutAmr ( orcID ) );
340
340
setupCallID (authtoken , orcID , APP_JSON , 200 , "bleah" );
341
341
failGetIdentities (idp , authCode , "pkce" , false , new IdentityRetrievalException (
342
342
"Unable to parse response from OrcID service." ));
343
343
344
- setUpCallAuthToken (authCode , authtoken , redir , cliid , clisec , "my name" , orcID );
344
+ setUpCallAuthTokenWithJWT (authCode , authtoken , redir , cliid , clisec , "my name" , orcID , createJWTWithoutAmr ( orcID ) );
345
345
setupCallID (authtoken , orcID , "text/html" , 200 , MAPPER .writeValueAsString (
346
346
map ("id" , "id1" , "displayName" , "dispname1" , "emails" , Arrays .asList (
347
347
map ("value" , "email1" )))));
348
348
failGetIdentities (idp , authCode , "pkce" , false , new IdentityRetrievalException (
349
349
"Unable to parse response from OrcID service." ));
350
350
351
- setUpCallAuthToken (authCode , authtoken , redir , cliid , clisec , "my name" , orcID );
351
+ setUpCallAuthTokenWithJWT (authCode , authtoken , redir , cliid , clisec , "my name" , orcID , createJWTWithoutAmr ( orcID ) );
352
352
setupCallID (authtoken , orcID , APP_JSON , 500 , STRING1000 );
353
353
failGetIdentities (idp , authCode , "pkce" , false , new IdentityRetrievalException (
354
354
"Got unexpected HTTP code and unparseable " +
355
355
"response from OrcID service: 500. Response: " + STRING1000 ));
356
356
357
- setUpCallAuthToken (authCode , authtoken , redir , cliid , clisec , "my name" , orcID );
357
+ setUpCallAuthTokenWithJWT (authCode , authtoken , redir , cliid , clisec , "my name" , orcID , createJWTWithoutAmr ( orcID ) );
358
358
setupCallID (authtoken , orcID , APP_JSON , 500 , STRING1001 );
359
359
failGetIdentities (idp , authCode , "pkce" , false , new IdentityRetrievalException (
360
360
"Got unexpected HTTP code and unparseable " +
@@ -398,8 +398,8 @@ private void getIdentityWithLoginURL(final String email, final Map<String, Objec
398
398
final IdentityProvider idp = new OrcIDIdentityProvider (idconfig );
399
399
final String orcID = "0000-0001-1234-5678" ;
400
400
401
- setUpCallAuthToken (authCode , "footoken3" , "https://ologinredir.com" ,
402
- idconfig .getClientID (), idconfig .getClientSecret (), " My name " , orcID );
401
+ setUpCallAuthTokenWithJWT (authCode , "footoken3" , "https://ologinredir.com" ,
402
+ idconfig .getClientID (), idconfig .getClientSecret (), " My name " , orcID , createJWTWithoutAmr ( orcID ) );
403
403
setupCallID ("footoken3" , orcID , APP_JSON , 200 , MAPPER .writeValueAsString (response ));
404
404
final Set <RemoteIdentity > rids = idp .getIdentities (authCode , "pkce" , false , null );
405
405
assertThat ("incorrect number of idents" , rids .size (), is (1 ));
@@ -416,15 +416,15 @@ public void getIdentityWithLoginURLAndEnvironment() throws Exception {
416
416
final IdentityProvider idp = new OrcIDIdentityProvider (idconfig );
417
417
final String orcID = "0000-0001-1234-5678" ;
418
418
419
- setUpCallAuthToken (authCode , "footoken3" , "https://lo.com" ,
420
- idconfig .getClientID (), idconfig .getClientSecret (), " My name " , orcID );
419
+ setUpCallAuthTokenWithJWT (authCode , "footoken3" , "https://lo.com" ,
420
+ idconfig .getClientID (), idconfig .getClientSecret (), " My name " , orcID , createJWTWithoutAmr ( orcID ) );
421
421
setupCallID ("footoken3" , orcID , APP_JSON , 200 , MAPPER .writeValueAsString (
422
422
map ("email" , Arrays .asList (map ("email" , "email7" )))));
423
423
final Set <RemoteIdentity > rids = idp .getIdentities (authCode , "pkce" , false , "e3" );
424
424
assertThat ("incorrect number of idents" , rids .size (), is (1 ));
425
425
final Set <RemoteIdentity > expected = new HashSet <>();
426
426
expected .add (new RemoteIdentity (new RemoteIdentityID (ORCID , orcID ),
427
- new RemoteIdentityDetails (orcID , "My name" , "email7" )));
427
+ new RemoteIdentityDetails (orcID , "My name" , "email7" , MfaStatus . NOT_USED )));
428
428
assertThat ("incorrect ident set" , rids , is (expected ));
429
429
}
430
430
@@ -454,9 +454,9 @@ private void getIdentityWithLinkURL(final String email, final Map<String, Object
454
454
final IdentityProvider idp = new OrcIDIdentityProvider (idconfig );
455
455
final String orcID = "0000-0001-1234-5678" ;
456
456
457
- setUpCallAuthToken (authCode , "footoken2" , "https://olinkredir2.com" ,
457
+ setUpCallAuthTokenWithJWT (authCode , "footoken2" , "https://olinkredir2.com" ,
458
458
idconfig .getClientID (), idconfig .getClientSecret (),
459
- null , orcID );
459
+ null , orcID , createJWTWithoutAmr ( orcID ) );
460
460
setupCallID ("footoken2" , orcID , APP_JSON , 200 , MAPPER .writeValueAsString (
461
461
response ));
462
462
final Set <RemoteIdentity > rids = idp .getIdentities (authCode , "pkce" , true , null );
@@ -483,16 +483,16 @@ public void getIdentityWithLinkURLAndEnvironment() throws Exception {
483
483
final IdentityProvider idp = new OrcIDIdentityProvider (idconfig );
484
484
final String orcID = "0000-0001-1234-5678" ;
485
485
486
- setUpCallAuthToken (authCode , "footoken2" , "https://li.com" ,
486
+ setUpCallAuthTokenWithJWT (authCode , "footoken2" , "https://li.com" ,
487
487
idconfig .getClientID (), idconfig .getClientSecret (),
488
- null , orcID );
488
+ null , orcID , createJWTWithoutAmr () );
489
489
setupCallID ("footoken2" , orcID , APP_JSON , 200 , MAPPER .writeValueAsString (
490
490
map ("email" , Arrays .asList (map ("email" , "email4" )))));
491
491
final Set <RemoteIdentity > rids = idp .getIdentities (authCode , "pkce" , true , "e3" );
492
492
assertThat ("incorrect number of idents" , rids .size (), is (1 ));
493
493
final Set <RemoteIdentity > expected = new HashSet <>();
494
494
expected .add (new RemoteIdentity (new RemoteIdentityID (ORCID , orcID ),
495
- new RemoteIdentityDetails (orcID , null , "email4" )));
495
+ new RemoteIdentityDetails (orcID , null , "email4" , MfaStatus . NOT_USED )));
496
496
assertThat ("incorrect ident set" , rids , is (expected ));
497
497
}
498
498
@@ -547,12 +547,15 @@ public void getIdentityWithNoJWT() throws Exception {
547
547
idconfig .getClientID (), idconfig .getClientSecret (), " My name " , orcID );
548
548
setupCallID ("footoken5" , orcID , APP_JSON , 200 , MAPPER .writeValueAsString (
549
549
map (
"email" ,
Arrays .
asList (
map (
"email" ,
"[email protected] " )))));
550
- final Set <RemoteIdentity > rids = idp .getIdentities (authCode , "pkce" , false , null );
551
- assertThat ("incorrect number of idents" , rids .size (), is (1 ));
552
- final Set <RemoteIdentity > expected = new HashSet <>();
553
- expected .add (new RemoteIdentity (new RemoteIdentityID (ORCID , orcID ),
554
- new RemoteIdentityDetails (
orcID ,
"My name" ,
"[email protected] " ,
MfaStatus .
UNKNOWN )));
555
- assertThat ("incorrect ident set" , rids , is (expected ));
550
+
551
+ // Now that JWT is required, this should fail with missing JWT error
552
+ try {
553
+ idp .getIdentities (authCode , "pkce" , false , null );
554
+ fail ("Expected IdentityRetrievalException" );
555
+ } catch (IdentityRetrievalException e ) {
556
+ assertThat ("incorrect exception message" , e .getMessage (),
557
+ is ("10030 Identity retrieval failed: No JWT token provided by ORCID despite requesting OpenID scope" ));
558
+ }
556
559
}
557
560
558
561
@ Test
0 commit comments