alternative for basic auth in Azure PowerShell runbook to authenticate office 365

Azure Learning 6 Reputation points
2022-10-18T07:44:40.14+00:00

Hi All,

OLD METHOD: Currently we are using basic authentication to authenticate office 365 account as below(basic Auth):
251476-image.png

NEW METHOD: so now we are trying to replace the above code with this code(Modern Auth)
251495-image.png

in both the above case, the username and password are stored under a Credential Object under the Credential tab in azure automation account.
so from that credential object we are first getting the username and password. then using those credentials we are authenticating office 365 account.

so will the new method(using modern auth) still work even after the removal of basic auth by microsoft from 1 oct 2022?
Can we store the credentials in credential object and use it in modern auth as shown above? even after the removal of basic auth by microsoft from 1 oct 2022?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,276 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,636 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Maxim Sergeev 6,571 Reputation points Microsoft Employee
    2022-10-18T15:59:20.817+00:00

    Hi there,

    I would recommend using SPN instead of username\passwiord pair. An example below

    https://lazyadmin.nl/powershell/azure-automation-authentication-and-runbooks/

    0 comments No comments

  2. Morten Lerudjordet 6 Reputation points
    2022-10-18T20:19:59.467+00:00

    Use a service principal to logon (with certificate), this is the way. Also check that you are running the latest module version of ExchangeOnlineManagement

    Example:
    Connect-ExchangeOnline -ShowBanner:$false -AppId $AzureConnection.ApplicationId -CertificateThumbprint $AzureConnection.CertificateThumbprint -Organization $ExchangeOrgName -ErrorAction Continue -ErrorVariable oErr
    if ($oErr)
    {
    Write-Error -Message "Failed to connect to Exchange Online with organization name: $ExchangeOrgName" -ErrorAction Stop
    }

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.