Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update device code and scope set for ADFS
  • Loading branch information
Santiago Gonzalez committed May 12, 2020
commit d0c280c3267432902a94cb2d01cef0f6e8010f2d
8 changes: 8 additions & 0 deletions lib/msal-common/src/authority/Authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export abstract class Authority {
}
}

public get deviceCodeEndpoint(): string {
if(this.discoveryComplete()) {
return this.tenantDiscoveryResponse.token_endpoint.replace("/token", "/devicecode");
} else {
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
}
}

/**
* OAuth logout endpoint for requests
*/
Expand Down
31 changes: 15 additions & 16 deletions lib/msal-common/src/client/DeviceCodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,23 @@ export class DeviceCodeClient extends BaseClient {
*/
private async getDeviceCode(request: DeviceCodeRequest): Promise<DeviceCodeResponse> {

const deviceCodeUrl = this.createDeviceCodeUrl(request);
const queryString = this.createQueryString(request);
const headers = this.createDefaultLibraryHeaders();

return this.executeGetRequestToDeviceCodeEndpoint(deviceCodeUrl, headers);
return this.executePostRequestToDeviceCodeEndpoint(this.defaultAuthority.deviceCodeEndpoint, queryString, headers);
// return this.executePostRequestToDeviceCodeEndpoint(`${this.defaultAuthority.canonicalAuthority}${Constants.DEVICE_CODE_ENDPOINT_PATH}`, queryString, headers);
}

/**
* Executes GET request to device code endpoint
* @param deviceCodeUrl
* @param deviceCodeEndpoint
* @param queryString
* @param headers
*/
private async executeGetRequestToDeviceCodeEndpoint(deviceCodeUrl: string, headers: Map<string, string>): Promise<DeviceCodeResponse> {
private async executePostRequestToDeviceCodeEndpoint(
deviceCodeEndpoint: string,
queryString: string,
headers: Map<string, string>): Promise<DeviceCodeResponse> {

const {
body: {
Expand All @@ -68,7 +73,12 @@ export class DeviceCodeClient extends BaseClient {
interval,
message
}
} = await this.networkClient.sendGetRequestAsync<ServerDeviceCodeResponse>(deviceCodeUrl, {headers});
} = await this.networkClient.sendPostRequestAsync<ServerDeviceCodeResponse>(
deviceCodeEndpoint,
{
body: queryString,
headers: headers
});

return {
userCode,
Expand All @@ -80,17 +90,6 @@ export class DeviceCodeClient extends BaseClient {
};
}

/**
* Create device code endpoint url
* @param request
*/
private createDeviceCodeUrl(request: DeviceCodeRequest): string {
const queryString: string = this.createQueryString(request);

// TODO add device code endpoint to authority class
return `${this.defaultAuthority.canonicalAuthority}${Constants.DEVICE_CODE_ENDPOINT_PATH}?${queryString}`;
}

/**
* Create device code endpoint query parameters and returns string
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-common/src/request/ScopeSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ScopeSet {
clientId: string,
scopesRequired: boolean,
) {
this.clientId = clientId;
this.clientId = clientId.toLowerCase();
this.scopesRequired = scopesRequired;

// Filter empty string and null/undefined array items
Expand Down
5 changes: 1 addition & 4 deletions lib/msal-common/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export const Constants = {
ADFS: "adfs",
// Default AAD Instance Discovery Endpoint
AAD_INSTANCE_DISCOVERY_ENDPT: "https://login.microsoftonline.com/common/discovery/instance",

// Device code endpoint path
DEVICE_CODE_ENDPOINT_PATH: "oauth2/v2.0/devicecode",
// Resource delimiter - used for certain cache entries
RESOURCE_DELIM: "|",
// Placeholder for non-existent account ids/objects
Expand Down Expand Up @@ -168,7 +165,7 @@ export enum SSOTypes {
ACCOUNT = "account",
SID = "sid",
LOGIN_HINT = "login_hint",
ID_TOKEN ="id_token",
ID_TOKEN = "id_token",
DOMAIN_HINT = "domain_hint",
ORGANIZATIONS = "organizations",
CONSUMERS = "consumers",
Expand Down