Skip to content

Bug report: app permission add fails when service principal not found #6289

@waldekmastykarz

Description

@waldekmastykarz

Priority

(Low) Something is a little off

Description

When in .m365rc.json you specify an Entra app for which you don't have a service principal, running the app permission add --grantAdminConsent command fails with Error: Cannot read properties of undefined (reading 'id')

Steps to reproduce

In .m365rc.json specify an ID of an app that exists in your directory but for which there's no service principal

Expected results

Running app permission add checks if the service principal exists, creates it if necessary, and grants admin consent

Actual results

Error: Cannot read properties of undefined (reading 'id')

Diagnostics

No response

CLI for Microsoft 365 version

Latest from main

nodejs version

v20

Operating system (environment)

macOS

Shell

zsh

cli doctor

No response

Additional Info

In this line:

await this.grantAdminConsent(appServicePrincipal!, appPermissions, logger);
we need to avoid the assumption that the SP exists. We need to check if it does, and creates it if it doesn't, like we do in
let appServicePrincipal = servicePrincipals.find(sp => sp.appId === appObject.appId);
if (!appServicePrincipal) {
appServicePrincipal = await this.createServicePrincipal(appObject.appId!, logger);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions