use of com.telenor.connect.id.IdToken in project connect-android-sdk by telenordigital.
the class IdTokenValidatorTest method authorizedPartyNotEqualClientThrows.
@Test(expected = ConnectException.class)
public void authorizedPartyNotEqualClientThrows() throws Exception {
BDDMockito.given(ConnectSdk.getConnectApiUrl()).willReturn(HttpUrl.parse("https://connect.telenordigital.com"));
BDDMockito.given(ConnectSdk.getClientId()).willReturn("connect-tests");
BDDMockito.given(ConnectSdk.getExpectedIssuer()).willReturn("https://connect.telenordigital.com/oauth");
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setIssuer("https://connect.telenordigital.com/oauth");
claimsSet.setAudience("connect-tests");
claimsSet.setExpirationTime(oneHourIntoFuture);
claimsSet.setIssueTime(now);
claimsSet.setCustomClaim("azp", "NOT connect-tests");
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), claimsSet);
signedJWT.sign(new ECDSASigner(new BigInteger("123")));
IdToken idToken = new IdToken(signedJWT.serialize());
IdTokenValidator.validate(idToken, null);
}
use of com.telenor.connect.id.IdToken in project connect-android-sdk by telenordigital.
the class IdTokenValidatorTest method missingIssueTimeThrows.
@Test(expected = ConnectException.class)
public void missingIssueTimeThrows() throws Exception {
BDDMockito.given(ConnectSdk.getConnectApiUrl()).willReturn(HttpUrl.parse("https://connect.telenordigital.com"));
BDDMockito.given(ConnectSdk.getClientId()).willReturn("connect-tests");
BDDMockito.given(ConnectSdk.getExpectedIssuer()).willReturn("https://connect.telenordigital.com/oauth");
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setIssuer("https://connect.telenordigital.com/oauth");
claimsSet.setAudience("connect-tests");
claimsSet.setExpirationTime(oneHourIntoFuture);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), claimsSet);
signedJWT.sign(new ECDSASigner(new BigInteger("123")));
IdToken idToken = new IdToken(signedJWT.serialize());
IdTokenValidator.validate(idToken, null);
}
use of com.telenor.connect.id.IdToken in project connect-android-sdk by telenordigital.
the class IdTokenValidatorTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
Calendar calendar = Calendar.getInstance();
now = calendar.getTime();
calendar.add(Calendar.HOUR, 1);
oneHourIntoFuture = calendar.getTime();
calendar.setTime(now);
calendar.add(Calendar.YEAR, 10);
tenYearsIntoFuture = calendar.getTime();
calendar.setTime(now);
calendar.add(Calendar.HOUR, -2);
twoHoursAgo = calendar.getTime();
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setIssuer("https://connect.telenordigital.com/oauth");
claimsSet.setAudience("connect-tests");
claimsSet.setExpirationTime(oneHourIntoFuture);
claimsSet.setIssueTime(now);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), claimsSet);
signedJWT.sign(new ECDSASigner(new BigInteger("123")));
normalSerializedSignedJwt = new IdToken(signedJWT.serialize());
}
use of com.telenor.connect.id.IdToken in project connect-android-sdk by telenordigital.
the class ConnectSdk method getSubjectId.
/**
* @return the subject's ID (sub), if one is signed in. Otherwise {@code null}.
* @deprecated use {@code getIdToken()} instead to access user information.
*/
@Deprecated
public static String getSubjectId() {
Validator.sdkInitialized();
IdToken idToken = sdkProfile.getConnectIdService().getIdToken();
return idToken != null ? idToken.getSubject() : null;
}
use of com.telenor.connect.id.IdToken in project connect-android-sdk by telenordigital.
the class IdTokenValidatorTest method expiredTimeThrows.
@Test(expected = ConnectException.class)
public void expiredTimeThrows() throws Exception {
BDDMockito.given(ConnectSdk.getConnectApiUrl()).willReturn(HttpUrl.parse("https://connect.telenordigital.com"));
BDDMockito.given(ConnectSdk.getClientId()).willReturn("connect-tests");
BDDMockito.given(ConnectSdk.getExpectedIssuer()).willReturn("https://connect.telenordigital.com/oauth");
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setIssuer("https://connect.telenordigital.com/oauth");
claimsSet.setAudience("connect-tests");
claimsSet.setExpirationTime(twoHoursAgo);
claimsSet.setIssueTime(now);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), claimsSet);
signedJWT.sign(new ECDSASigner(new BigInteger("123")));
IdToken idToken = new IdToken(signedJWT.serialize());
IdTokenValidator.validate(idToken, null);
}
Aggregations