Azure AD sign in for mobile application remove prompt consent - mobile

Is it possible to remove the consent prompt when user sign in to the mobile application?

Please check if below points can help:
For the mobile app registered in azure ad,please make sure the api permissions like delegated user permissions (This will allow minimum compulsory permissions to be needed .) added are given/granted consent in portal itself by admin. If required add users to the application that dont need consent .
If you want the user to be verified first by the admin , don't grant it and grant after the login request for the first time.
For users in your tenant to allow access to the application, please
Go to your Azure AD > Enterprise Applications > User settings > Admin consent requests
Here select Users can request admin consent to apps they are unable to consent to to Yes .
For ‘Who can review admin consent requests’, select the users and groups whom you can allow to review the admin consent for the application and set the days till when this consent is not required for those user. This way users in your tenant will not receive the admin consent prompt while trying to access the application.
Select Allow user consent for apps in User consent settings pane if you permanently need to remove consent for all applications in your tenant.

Related

How to cancel user consent to a web application

I recently logged into a web application and I got the standard user consent dialog.
I clicked "Accept".
How do I get to that dialog again or cancel?
Thanks
You cannot cancel the user's consent to the web application through the UI. You can revoke the administrator's consent to the application through the Azure portal. However, this obviously does not apply to the user's consent.
However, you can cancel user consent through power shell. First go to Enterprise Applications>your application>Permissions>User consent and you will see all user consent permissions.
Next, you can then click Review permissions -> This application has more permissions than I want. This will give you a PowerShell script that you can run to remove all user consent for that application. It can of course be customized to only remove certain permissions.

Azure OAuth2 flow when approval is requested

Our app implements Azure OAuth2 (v2) user-consent flow and uses Graph API scopes that do not require admin consent oauth2 user. Recently we've noticed that some users of our app run into this Auth screen: "The app requires admin's approval".
Is that because the tenant Org disabled user-consent for apps?
Where does it leave us with the user-consent based OAuth2 flow? Is it still possible to get a user access token after an admin's approval or the only way is to use the OAuth2 daemon flow oauth2 daemon? In a callback after such a dialog how can we know that the admin approval has been given?
One related question. In cases where user-consent is not disabled but it's an admin user that authorizes there is an option 'Consent on behalf of your Organization". How can we know in the callback from this dialog that the admin checked that box? And does it mean we need to use the OAuth2 daemon flow then too?
Thank you
It was our lack of understanding. After more testing we realized that we used prompt=consent and that is why the consent window always showed. Thank you.
Is that because the tenant Org disabled user-consent for apps?
Yes, this settings is under Enterprise applications->User settings.
Is it still possible to get a user access token after an admin's
approval
Yes, you can still get a user access token after an admin's approval.
In a callback after such a dialog how can we know that the admin
approval has been given?
Once your admin reviews the request you will be notified via email.
In cases where user-consent is not disabled but it's an admin user
that authorizes there is an option 'Consent on behalf of your
Organization". How can we know in the callback from this dialog that
the admin checked that box?
Once the admin checked the box, the users under that tenant will not see the consent dialog. Also, you can check the status of the application in Azure portal->App registrations->your app->API permissions.
There are two possible reasons users consent or adminconsent
For user consent two possible cases
1)In a tenant where user consent is disabled, for example, users can't consent to any permission. Azure AD-- > Enterprise apps ---> User settings ---> Users can consent to apps.
2) User assignment :Azure AD--- > Enterprise apps-- > (select app) --> Properties --> User assignment required
For Admin Consent two possible cases
1) App-only permissions always require a tenant administrator’s consent. If your application requests an app-only permission and a user tries to sign in to the application, an error message is displayed saying the user isn’t able to consent.
2) Certain delegated permissions also require a tenant administrator’s consent. For example, the ability to write back to Azure AD as the signed in user requires a tenant administrator’s consent.
Solution :
The prompt=admin_consent parameter(which request permissions from admin) can be used as a parameter in the OAuth2/OpenID Connect authorization request to grant the admin consent .
Enable the admin consent workflow , which gives end users a way to request access to applications that require admin consent.
Refer the permissions documentation for the Microsoft Graph API indicate which permissions require admin consent.

Azue AD asks for admin consent for Power BI Access

I want to use AAD for PowerBI Rest API and thus need to get Token for auth. Even the permission granted to App does not need Admin consent yet, I always receive a popup saying:
<App> needs permission to access resources in your
organization that only an admin can grant. Please ask an admin to
grant permission to this app before you can use it.
App API Permissions (see no where it requires Admin consent)
Code I am using for auth:
var userAuthnResult = authenticationContext.AcquireTokenAsync(
ProgramConstants.PowerBiServiceResourceUri,
ProgramConstants.ClientID,
new Uri(ProgramConstants.RedirectUri),
new PlatformParameters(PromptBehavior.Auto)).Result;
P.S I have tried auth. using creds which is not working for me due to multi-factor auth on my org.
var userAuthnResult = authenticationContext.AcquireTokenAsync(
ProgramConstants.PowerBiServiceResourceUri,
ProgramConstants.ClientID,
userCreds).Result;
If your organization has disabled or restricted users' authorization to consent to applications, you won't be able to grant consent yourself, even if the permissions your app is requesting don't require admin intervention.
You can check if user consent is enabled or disabled in your organization in the Azure portal > Azure AD > Enterprise apps > User settings. (Even if you're not an administrator, you should be able to see if the switch it on or off.)

Applications created in v2 endpoint, how to grant admin consent for all users in my tenant

For v1 app registered in portal, you can 'Grant Permissions' to consent to an application's delegated permissions on behalf of all the users in your tenant. For an app registered in v2 endpoint, can only see it in the 'Enterprise Applications' tab and there is no option for 'grant permissions' in the permissions tab. How to get to the same goal that I do not want individually consent each user?
Edit: after make the adminconsent call,
This worked, (with only graph scope)
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=myappid&response_type=code&response_mode=query&scope=openid profile email offline_access https%3A%2F%2Fgraph.microsoft.com%2FCalendars.ReadWrite%20https%3A%2F%2Fgraph.microsoft.com%2FContacts.ReadWrite%20https%3A%2F%2Fgraph.microsoft.com%2FMail.ReadWrite%20https%3A%2F%2Fgraph.microsoft.com%2FUser.Read&state=12345&redirect_uri=redirecturl
This still give me a AADSTS90094 error and ask for admin consent, (with openid scopes)
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=myappid&response_type=code&response_mode=query&scope=openid profile email offline_access https%3A%2F%2Fgraph.microsoft.com%2FCalendars.ReadWrite%20https%3A%2F%2Fgraph.microsoft.com%2FContacts.ReadWrite%20https%3A%2F%2Fgraph.microsoft.com%2FMail.ReadWrite%20https%3A%2F%2Fgraph.microsoft.com%2FUser.Read&state=12345&redirect_uri=redirecturl
Edit:
This issue happens only when I turn on 'User Assignment Required' flag
in azure portal, if that flag is disabled, users will be able to individually consent and login, no issues, however we need this flag since we do not want all our users in AD be able to use the app.
To request consent for all users in a tenant in Azure AD V2.0, your app can use the admin consent endpoint:
GET https://login.microsoftonline.com/{tenant}/adminconsent?
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&state=12345
&redirect_uri=http://localhost/myapp/permissions
Please refer to docunment : Using the admin consent endpoint
The listings in the enterprise apps tab are all service principals rather than app registrations. These are apps that your tenant has signed into & consented thus provisioning the service principal into the tenant.
v2 apps are created and managed through the App Registration Portal; however, there is no equivalent functionality to Grant Permissions at this time. In order to perform admin consent in v2, you have to construct a request to Azure AD.
Just go to your browser and drop the following request (populated with your regisered apps Client/App ID & Redirect URI:
https://login.microsoftonline.com/{tenant}/adminconsent?client_id=<Client/App ID>&redirect_uri=<App's Redirect URI>&state=111

Azure AD admin consent required when it shouldn't

I have 2 tenants:
One for my organization, where I manage users (A)
One that I manage the applications and permissions (B)
My webapp is on tenant A and I configured authentication on the portal using Azure AD on tenant B.
On tenant B I registered the application with only one permission which does not require admin consent: Windows Azure Active Directory > Sign in and read user profile.
When the user logs in he gets the following error:
AADSTS90093: This operation can only be performed by an administrator. Sign out and sign in as an administrator or contact one of your organization's administrators.
I believe that this error should not be raised, since the only permission required by the application doesn't required admin.
EDIT
This is the URL that I am redirected to when I try to access the application when I'm not logged in
https://login.microsoftonline.com/d6ac45af-3289-4f79-a826-27824e1c467d/oauth2/authorize?response_type=code+id_token&redirect_uri=https%3A%2F%2Ftechnipfmc-tools-app-test.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&client_id=d340f0ed-5eb3-43e8-9a50-c449649f3ee1&scope=openid+profile+email&response_mode=form_post&nonce=1895ec0ffef64447bbb712bdae61c7fb_20170521070654&state=redir%3D%252F
EDIT 2
I found out a solution here:
As an administrator, you can also consent to an application's delegated permissions on behalf of all the users in your tenant. This will prevent the consent dialog from appearing for every user in the tenant. You can do this from the Azure portal from your application page. From the Settings blade for your application, click Required Permissions and click on the Grant Permissions button.
I don't know why had to do that since I'm only using permissions that don't require admin consent.
There are several potential problems with your setup:
Your authorization request is set to a specific tenant, the one with tenantId d6ac45af-3289-4f79-a826-27824e1c467d. Only users from that tenant will be able to log in. If this tenantId corresponds to the one for your organization, where you manage users (A), then disregard this point. Otherwise you should either replace this with the tenantId of that tenant or with common which will allow users from any tenant to sign in.
Your application is not multi-tenant. For testing purposes, I replaced the tenantId with common and wasn't able to use this with my test tenant due to the following error: AADSTS70001: Application with identifier 'd340f0ed-5eb3-43e8-9a50-c449649f3ee1' was not found in the directory <MY_TEST_TENANT>. This indicates that the application isn't configured as a multi-tenant application. This is something you must explicitly turn on.
Your organization's tenant (A) might have disabled the ability for regular users to consent to applications. If this capability is disabled, admin consent is always required for the application to be set up in the tenant. To test to see if this is the case, address points #1 (use /common/) and #2 above and try with any other tenant. If you are able to consent with that other tenant but not your organization's tenant, then you'll know that admin consent is required for your organization.
You should check out the How to sign in any Azure Active Directory (AD) user using the multi-tenant application pattern article as it explains all of the points above in more detail.
I think that error appears when you are passing "&prompt=admin_consent" in the Login URL.
Even though you are not requesting Admin permissions, if you pass that query string, it will try to show you a consent dialogue so that you can consent on behalf of the whole tenant, which is an operation that only an admin can do.

Resources