Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ final class AuthenticationResult implements IAuthenticationResult {
private final Long refreshOn;
private final String familyId;
private final String idToken;
private final IdToken idTokenObject = getIdTokenObj();
private final IdToken idTokenObject;
private final AccountCacheEntity accountCacheEntity;
private final IAccount account = getAccount();
private final ITenantProfile tenantProfile = getTenantProfile();
private final IAccount account;
private final ITenantProfile tenantProfile;
private String environment;
private final Date expiresOnDate;
private final String scopes;
Expand All @@ -40,14 +40,21 @@ final class AuthenticationResult implements IAuthenticationResult {
this.metadata = metadata == null ? AuthenticationResultMetadata.builder().build() : metadata;
this.isPopAuthorization = isPopAuthorization;
this.expiresOnDate = new Date(expiresOn * 1000);
this.idTokenObject = getIdTokenObj();
this.account = getAccount();
this.tenantProfile = getTenantProfile();
}

private IdToken getIdTokenObj() {
if (StringHelper.isBlank(idToken)) {
return null;
}

return JsonHelper.createIdTokenFromEncodedTokenString(idToken);
try {
return JsonHelper.createIdTokenFromEncodedTokenString(idToken);
} catch (Exception e) {
return null;
}
}

private IAccount getAccount() {
Expand All @@ -62,7 +69,16 @@ private ITenantProfile getTenantProfile() {
return null;
}

return new TenantProfile(JsonHelper.parseJsonToMap(JsonHelper.getTokenPayloadClaims(idToken)), getAccount().environment());
IAccount acct = getAccount();
if (acct == null) {
return null;
}

try {
return new TenantProfile(JsonHelper.parseJsonToMap(JsonHelper.getTokenPayloadClaims(idToken)), acct.environment());
} catch (Exception e) {
return null;
}
}

public String accessToken() {
Expand Down Expand Up @@ -114,7 +130,7 @@ AccountCacheEntity accountCacheEntity() {
}

public IAccount account() {
return getAccount();
return this.account;
}

public ITenantProfile tenantProfile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.microsoft.aad.msal4j;

import java.io.Serializable;
import java.util.Objects;

/**
* Contains metadata and additional context for the contents of an AuthenticationResult
Expand Down Expand Up @@ -59,6 +60,26 @@ void cacheRefreshReason(CacheRefreshReason cacheRefreshReason) {
this.cacheRefreshReason = cacheRefreshReason;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AuthenticationResultMetadata)) return false;

AuthenticationResultMetadata other = (AuthenticationResultMetadata) o;

return Objects.equals(tokenSource, other.tokenSource)
&& Objects.equals(refreshOn, other.refreshOn)
&& Objects.equals(cacheRefreshReason, other.cacheRefreshReason);
}

@Override
public int hashCode() {
int result = tokenSource == null ? 0 : tokenSource.hashCode();
result = 31 * result + (refreshOn == null ? 0 : refreshOn.hashCode());
result = 31 * result + (cacheRefreshReason == null ? 0 : cacheRefreshReason.hashCode());
return result;
}

public static class AuthenticationResultMetadataBuilder {
private TokenSource tokenSource;
private Long refreshOn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public DeviceCodeFlowParametersBuilder scopes(Set<String> scopes) {
* Cannot be null.
*/
public DeviceCodeFlowParametersBuilder deviceCodeConsumer(Consumer<DeviceCode> deviceCodeConsumer) {
validateNotNull("deviceCodeConsumer", scopes);
validateNotNull("deviceCodeConsumer", deviceCodeConsumer);

this.deviceCodeConsumer = deviceCodeConsumer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ static ErrorResponse fromJson(JsonReader jsonReader) throws IOException {
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();

jsonWriter.writeStartObject();

jsonWriter.writeNumberField("statusCode", statusCode);
jsonWriter.writeStringField("statusMessage", statusMessage);
jsonWriter.writeStringField("error", error);
Expand Down
29 changes: 29 additions & 0 deletions msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IdToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;

class IdToken implements Serializable, JsonSerializable<IdToken> {

Expand Down Expand Up @@ -101,4 +102,32 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {

return jsonWriter;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IdToken)) return false;

IdToken other = (IdToken) o;

return Objects.equals(issuer, other.issuer)
&& Objects.equals(subject, other.subject)
&& Objects.equals(audience, other.audience)
&& Objects.equals(expirationTime, other.expirationTime)
&& Objects.equals(issuedAt, other.issuedAt)
&& Objects.equals(notBefore, other.notBefore)
&& Objects.equals(name, other.name)
&& Objects.equals(preferredUsername, other.preferredUsername)
&& Objects.equals(objectIdentifier, other.objectIdentifier)
&& Objects.equals(tenantIdentifier, other.tenantIdentifier)
&& Objects.equals(upn, other.upn)
&& Objects.equals(uniqueName, other.uniqueName);
}

@Override
public int hashCode() {
return Objects.hash(issuer, subject, audience, expirationTime, issuedAt,
notBefore, name, preferredUsername, objectIdentifier,
tenantIdentifier, upn, uniqueName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static OidcDiscoveryResponse fromJson(JsonReader jsonReader) throws IOExc

public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("issuer", issuer);
jsonWriter.writeStringField("authorization_endpoint", authorizationEndpoint);
jsonWriter.writeStringField("token_endpoint", tokenEndpoint);
jsonWriter.writeStringField("device_authorization_endpoint", deviceCodeEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public RefreshTokenParametersBuilder scopes(Set<String> scopes) {
* Cannot be null.
*/
public RefreshTokenParametersBuilder refreshToken(String refreshToken) {
validateNotNull("refreshToken", scopes);
validateNotNull("refreshToken", refreshToken);

this.refreshToken = refreshToken;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();

if (name != null && requestedClaimAdditionalInfo != null) {
jsonWriter.writeString(name);
jsonWriter.writeFieldName(name);
requestedClaimAdditionalInfo.toJson(jsonWriter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.microsoft.aad.msal4j;

import java.util.Map;
import java.util.Objects;

/**
* Representation of a single tenant profile
Expand Down Expand Up @@ -40,4 +41,20 @@ public TenantProfile environment(String environment) {
this.environment = environment;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TenantProfile)) return false;

TenantProfile other = (TenantProfile) o;

return Objects.equals(idTokenClaims, other.idTokenClaims)
&& Objects.equals(environment, other.environment);
}

@Override
public int hashCode() {
return Objects.hash(idTokenClaims, environment);
}
}
Loading