Single sign-on to Azure portal - azure

Is there any option to sign-in to Azure portal using clientID, client Secret, Tenant ID and /or subscription ID? Most of the samples I saw are using AD or SAML

No, you can't.
If you get the sign in url of the azure portal, you will find it uses this flow to authorize.
https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?
client_id=c44b4083-3bb0-49c1-b47d-974e53cbdf3c&
response_mode=form_post&
response_type=code+id_token&
scope=https%3a%2f%2fmanagement.core.windows.net%2f%2fuser_impersonation+openid+email+profile&
state=OpenIdConnect.AuthenticationProperties%3d5sSBWCgxO8uzYlVgeWTBnBpO_3udn25WSlg2P5mZjzotjbc0u3aiZfTvDwyVNboeIldUVKig-KNmc_LiG_a2LI4dySYHViQ1bEQgXUt1c7PbCQ4Nqg-VOu9nsnSwTZ4i15w_0XeNah_PvG8B0TgQI5D-AlN4lhNrwtjN8ATClowc38Ifdu7h8BweU3sGvxlvYxtBG3-VzwSty-jaDbz3CRTUFmm0jTTKOGPrHsGu3q6-R9pDKFqvZk50Cd6AstdLe4qpcTRxFlkb114JxGW0BzZKIy__sIbqkHm_WeMnaFBGuQaTcGv4e7EizLxbZUc_jpqopZRCw7sfv-eaxHrD_ZoaXzNtylfoVnfcrnK0cbvh1TopnOcY166ZFW4uQlFu73De9SPMKMVr53gaUJTfR_pdJBQ_hS51L4quMf_noP4x5szhQ314hxgwoJBnw7R_8vhBKF6jplZmhqf3Hrsp4nEyzjjbyocCoXF9qxJjLkY&
nonce=637188980051547113.OTZkOTdlYjctODJiNS00M2E1LWFjZWUtM2FlMTUyYmJmOTc0ZWUxOWQ1OTYtNTBhOC00ZTc0LWFmMGYtNDkwYTA3ODJkZmEx&
redirect_uri=https%3a%2f%2fportal.azure.com%2fsignin%2findex%2f%3ffeature.refreshtokenbinding%3dtrue%26feature.snivalidation%3dtrue%26feature.usemsallogin%3dtrue&site_id=501430&client-request-id=c171ca99-bd9c-4a38-aaa0-a9344d273131&x-client-SKU=ID_NET&x-client-ver=1.0.40306.1554
Actually the azure portal is an AD App registered in azure ad, so you need the user account to login.
If you want to use the service principal(i.e. the clientID you mentioned) to do operations on the azure resources, you could use the Azure powershell, CLI, REST API.
Samples:
1.Use the service principal to login Azure powershell
$passwd = ConvertTo-SecureString <use a secure password here> -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential('service principal name/id', $passwd)
Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId
2.Use the service principal to login Azure CLI
az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p VerySecret --tenant contoso.onmicrosoft.com
3.Use the client credential flow to get the token, then use it to call the REST API, see this link.

Related

How can i login to Azure using an account with MFA using Powershell?

I am currently logging int Azure using
az login -u -p ""
The issue is that the email is MFA and a verification code is needed to be entered in.
This login process is used for CICD. Is there a way I can automate this process without having to enter the verification code
Thank you for your valuable suggestion and for directing in the right direction, #fmarz10.
Service principals with various forms of credentials, such as passwords, secret keys, and certificates, can be used to do this.
After adding the role you can automate login using
$azureAplicationId ="Your Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$psCred = New-Object >System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId ->ServicePrincipal
REFERENCES
Azure Service Principals
Sign in with Azure PowerShell
Azure Provisioning - Without manual login

AAS Unable to obtain authentication token using the credentials provided

Currently, we are using Service account to refresh the Azure Analysis Service Tabular model using the Azure Automation account and now planning to move to Service principal
Below are the steps I followed to do the required setup:
Create a Run as accounts from the Automation Account screen
The above step created a Service Principal in Azure Active Directory and using this I created a Client Secret. After this, I picked up the below values from the Service Principal:
Application (client) ID
Object ID
Directory (tenant) ID
Client Secret ID
Then, I have created a Credential in the Automation Account page using the <Application (client) ID> and <in the Azure Automation account
Username: <Application (client) ID>
Password:
Edited the Automation account Runbook to fetch the Service Principal credentials and then refresh the Azure Analysis Service. Below is the script:
#Tls 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#Base Values
$databaseName = "Reporting-Tabular"
$server = "asazure://.asazure.windows.net/AASServer"
#Get Creds
$Credential = Get-AutomationPSCredential -Name 'service-principal'
Write-Output "Credential Obtained, invoking refresh"
Invoke-ProcessASDatabase -DatabaseName $databaseName -RefreshType "Full" -Server $server - ServicePrincipal -Credential $Credential
Write-Output "Done!"*
Added the app:<Application (client) ID>#<Directory (tenant) ID> to the Azure Analysis Services admin list using SSMS
I am getting the below error when I test the run book using the Test pane in the Automation account:
Unable to obtain authentication token using the credentials provided.
Please help how to resolve this issue.
in the Automation Credential password try pasting app registration's secret value instead of secret id.

Reset the client secret of Azure Service Principal using powershell

Using powershell commands i want to reset the Service Principal client secret.
I followed the below steps from the article https://learn.microsoft.com/en-us/powershell/azure/create-azure-service-principal-azureps?view=azps-5.8.0
but it didnot reset the password
Remove-AzADSpCredential -DisplayName ServicePrincipalName
$newCredential = New-AzADSpCredential -ServicePrincipalName ServicePrincipalName
can you tell what i am doing wrong. I just want to reset the secret and have new one
I executed the above command and then i went to the app registration of that service principal and there i went to certificates & secrets i see it has not createed new secret.
Using bash i am able to reset the password by executing the below command but i want it to be done using powershell command
az ad sp credential reset --name
I went to the app registration of that service principal and there I went to certificates & secrets I see it has not created new secret.
Well, actually the command New-AzADSpCredential did create a new secret for you.
Firstly, you need to know the relationship between App Registration(AD App) and Service principal, see Application and service principal objects in Azure Active Directory.
In short, the service principal is the local representation for the AD App in a specific tenant. When you create the secret for the service principal, it will not appear in the Certificates & secrets blade, you can just get it with Get-AzADSpCredential.
If you want to reset the secret that you can find in the portal, you need to reset the sceret for the AD App(i.e. App Registration) via Remove-AzADAppCredential and New-AzADAppCredential.
You could refer to the sample below, it resets a secret with value ce96a0ed-5ae8-4a5a-9b3c-630da9ea3023, it is valid for one year, you can find it in the portal.
$obj = (Get-AzADApplication -DisplayName joyappv2).ObjectId
Remove-AzADAppCredential -ObjectId $obj -Force
$azurePassword = ConvertTo-SecureString "ce96a0ed-5ae8-4a5a-9b3c-630da9ea3023" -AsPlainText -Force
$date = Get-Date
$newCredential = New-AzADAppCredential -ObjectId $obj -Password $azurePassword -StartDate $date -EndDate $date.AddYears(1)
Note: You could not get the secret value again after creating it, so please store it when creating.

How to create Service Principal of Multi-tenant Application

I have created new Azure AAD Application with Multi-tenant enabled. But i Couldn't find App in another tenant ID. When i try to create a Service Principal of above App ID in another Tenant.It is failing with error "New-AzureRmADServicePrincipal : When using this permission, the backing application of the service principal being created must in the local tenant" . Has anyone experience such issue.
$StartDate = [DateTime]::UtcNow
$EndDate = [DateTime]::UtcNow.AddYears(3)
$secureString = convertto-securestring "XXXXXXXXX" -asplaintext -force
New-AzureRmADServicePrincipal -ApplicationId "XXXXXXXXXX" -Password $secureString -StartDate $StartDate -EndDate $EndDate
I fixed my question using following PS command
Connect-AzureAD -TenantId '<TargetTenant>'
New-AzureADServicePrincipal -AppId 'ThirdPartyAppID'
I couldn't reproduce this error. New-AzureRmADServicePrincipal -ApplicationId "XXXXXXXXXX" works fine for me to create the enterprise app in another tenant.
If you want to add the multi-tenant app into another tenant, there is another way. You can have a try with the admin consent.
I assume that your app is registered in tenant_x and want to add it into tenant_y.
You can redirect the user to the Microsoft identity platform admin consent endpoint.
GET https://login.microsoftonline.com/{tenant_y}/v2.0/adminconsent?
client_id={client id}
&state=12345
&redirect_uri={redirect_uri}
&scope=
https://graph.microsoft.com/calendars.read
https://graph.microsoft.com/mail.send
Access it in a broswer and log in with an admin account of tenant_y to do the admin consent. After that the app will be added into tenant_y.

Method to get list of AD users using application password

In an application, I'm currently using PowerShell and MSOnline module (Connect-MsolService and Get-MsolUser) to get a list of AD users. A global admin provides his username and password and the application is able to get a list of all users under that tenant.
That works fine... As long as the password is not an app password. When an app password is used then the following is what the global admin gets to see:
Authentication Error: Bad username or password
My question is: Is there any other method, which uses PowerShell, but doesn't have to, to get the list of users in AD, but which works with app password? I know of Graph API, but that's not a fit for the project right now.
If I understand you correctly, you want to use the AD App and its password(secret) to list the users.
You could use the Az powershell module to do that, login with the service principal and list users via Get-AzADUser. Also, make sure your AD App(service principal) has the admin role like User administrator or Global administrator.
$azureAplicationId ="<AD App Application id>"
$azureTenantId= "<tenant id>"
$azurePassword = ConvertTo-SecureString "<password>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
Get-AzADUser
Update:
Currently, use app password of MFA enabled user to connect MSOL powershell is not supported, for more details see this link.
App passwords are NOT supported, simply use Connect-MsolService without any parameter to trigger the ADAL dialog and complete the 2FA challenge as normal.

Resources