Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes login validation for system-assigned managed identity #6528

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions src/m365/commands/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ describe(commands.LOGIN, () => {
assert.strictEqual(auth.connection.userName, undefined, 'Incorrect userName set');
});

it('logs in to Microsoft 365 using system-assigned managed identity when authType identity set', async () => {
await command.action(logger, {
options: commandOptionsSchema.parse({
authType: 'identity'
})
});
assert.strictEqual(auth.connection.authType, AuthType.Identity, 'Incorrect authType set');
});

it('logs in to Microsoft 365 using client secret authType "secret" set', async () => {
await command.action(logger, {
options: commandOptionsSchema.parse({
Expand Down
12 changes: 6 additions & 6 deletions src/m365/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ class LoginCommand extends Command {

public getRefinedSchema(schema: typeof options): z.ZodEffects<any> | undefined {
return schema
.refine(options => typeof options.appId !== 'undefined' || cli.getClientId(), {
message: `appId is required. TIP: use the "m365 setup" command to configure the default appId`,
.refine(options => typeof options.appId !== 'undefined' || cli.getClientId() || options.authType === 'identity', {
message: `appId is required. TIP: use the "m365 setup" command to configure the default appId.`,
path: ['appId']
})
.refine(options => options.authType !== 'password' || options.userName, {
message: 'Username is required when using password authentication',
message: 'Username is required when using password authentication.',
path: ['userName']
})
.refine(options => options.authType !== 'password' || options.password, {
message: 'Password is required when using password authentication',
message: 'Password is required when using password authentication.',
path: ['password']
})
.refine(options => options.authType !== 'certificate' || !(options.certificateFile && options.certificateBase64Encoded), {
Expand All @@ -71,13 +71,13 @@ class LoginCommand extends Command {
options.certificateBase64Encoded ||
cli.getConfig().get(settingsNames.clientCertificateFile) ||
cli.getConfig().get(settingsNames.clientCertificateBase64Encoded), {
message: 'Specify either certificateFile or certificateBase64Encoded',
message: 'Specify either certificateFile or certificateBase64Encoded.',
path: ['certificateFile']
})
.refine(options => options.authType !== 'secret' ||
options.secret ||
cli.getConfig().get(settingsNames.clientSecret), {
message: 'Secret is required when using secret authentication',
message: 'Secret is required when using secret authentication.',
path: ['secret']
});
}
Expand Down
Loading