How does SqlClient gets 'scope' of Azure SQL Server when using Azure Active Directory as authentication method? - azure-active-directory

As I understand that for getting selective authorization for a protected resource using Azure AD based OAuth 2.0 mechanism, client application need to mandatorily provide the scope URL for getting access token.
Other parameters usually include client ID, client secret (in case of Service Principal auth flow), Azure AD username and password, etc.
SqlClient has integrated Azure AD OAuth mechanism with SqlClient for authorizing a database connection.
So, I guess SqlClient also need these parameters for establishing an connection to Azure SQL server using Azure Active Directory authentication method.
But I don't see that it accepts any scope from the client application.
How does SqlClient gets scope for a particular Azure SQL server instance? I see that it gets something as Federated Authentication Info from server but I don't understand it completely.

The scope required for SQL Servder Authentication access tokens is https://database.windows.net/.default which stands for default scopes/permissions for https://database.windows.net/ resource.
Once an access token is obtained you pass it trough the SqlConnection.AccessToken property.

Related

Is it possible to connect to snowflake in Azure Databricks using Oauth token from an existing Service Principal?

I am trying to connect to Snowflake in Databricks using an Azure access token generated from an existing Service Principal (not using the documentation's method to create one as I don't have the permissions to). Currently I am receiving the error "Invalid OAuth access token".
I believe the solution is I need snowflake to grant access to the service principal, however not sure how to do this or if it is even possible?
According to this Snowflake document, programmatic SSO with Federated Authentication (like you would need in a Databricks notebook) is only available for the Okta identity provider - even though Microsoft Azure Active Directory is among their supported Identity Providers

JDBC using Azure Active Directory credentials

I'm getting wrong username or password when trying to make a JDBC connection to snowflake. I believe the culprit is that there is an Azure Active Directory layer between the connection. Is there a specific way I should be handling making this connection while using the azure credentials from my Java app through Azure Active Directory to Snowflake? Thanks in advance!
In your JDBC connection parameters, you need to set the authenticator parameter to externalbrowser or possibly depending on the setup oauth with a setting for the oauth token parameter.
You can read more about OAuth here, https://docs.snowflake.com/en/user-guide/oauth-custom.html
The section specific to OAuth on JDBC on that page is here, https://docs.snowflake.com/en/user-guide/jdbc-configure.html#label-jdbc-connection-parameters. Scroll down from that bookmark on the page to the authenticator parameter section.

Azure bus integration with GO based application

We are trying to connect to Azure service bus entity from "GO" language application & the integration with Azure service bus entity is possible by supplying either SAS token or Azure AD OAuth2.0 token which will be obtained via security principals. Technically I prefer security principals option rather than SAS token as it has security vulnerabilities.
How to acquire OAuth2.0 token from Azure AD using language like "GO" for which Azure AD SDK is not available?
Is it possible to make direct call to Azure AD REST APIs to access OAuth2.0 token? if yes some code sample would be helpful otherwise please suggest suitable options.
Here are available authentication methods for Go.
Also, you can make a direct call to get the access token.
https://login.microsoftonline.com/{tenant}/oauth2/token
Reference:
OAuth 2.0 client credentials grant
Authenticate and authorize an application with Azure Active Directory to access Azure Service Bus entities

OpenId Connect accessing both graph api and on prem resource with single login

Trying to get a ASP.NET web application to access both a local resource and graph api using a single login.
The environment consists of a on prem adfs as well as a Azure AD instance that is synced and federated against on prem ad.
I have the following working.
Configure the application to use OpenId Connect authentication against Azure AD with a client configured in azure ad. The user authenticates and i receive a authentication code that i can use to get a token to call graph api successfully.
Configure the application to use OpenId Connect authentication against ADFS using a client_id configured in ADFS. The user authenticates and i get a authentication code that i use to get a bearer token to call the local resource.
However i cannot find a way to get access to both the local resource and graph api with a single login. Is this at all possible? Could someone point me in the right direction?
You can use a Delegated token which contains both a valid Client and User.
See the documentation and Stackoverflow thread.
If it is just read-access and not write-access then what you are describing should be possible.

ADFS roles from SQL Server

Scenario: In an intranet application, ADFS uses AD for authentication(Account Store) and Sql server for authorization(roles/Attribute Store).
The roles are my own application specific. There are other applications that need to use ADFS. If ADFS is configured to use my SQL Server to fetch roles, what would other applications do? How will they manage their authorization?
Is my understanding correct? If yes, please verify my answer:
Ans: ADFS just returns me the AD identifier(SID/Name).I map this to my sql server roles. Role management should be done by my own application connecting to Sql server. Use session to prevent hitting DB for authorization every time.
To avoid hitting the SQL server for every authorization check, you could implement claims based authentication. Use the SQL attribute store to add your role claims to the AD user ID claims. The resulting claims ticket (SAML) is sent as a cookie and isn't fetched on every authentication check as it is kept as a cookie by the user browser available to the server on each and every request. The timeout/refresh can be set by ajusting the claims ticket TTL (time to live).Just a suggestion... =o)

Resources