You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-sql/database/authentication-azure-ad-logins-tutorial.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -196,6 +196,13 @@ The [ALTER LOGIN (Transact-SQL)](/sql/t-sql/statements/alter-login-transact-sql?
196
196
ALTER LOGIN [bob@contoso.com] DISABLE
197
197
```
198
198
199
+
For the `DISABLE` or `ENABLE` changes to take immediate effect, the authentication cache and the **TokenAndPermUserStore** cache must be cleared using the following T-SQL commands:
200
+
201
+
```sql
202
+
DBCC FLUSHAUTHCACHE
203
+
DBCC FREESYSTEMCACHE('TokenAndPermUserStore') WITH NO_INFOMSGS
204
+
```
205
+
199
206
Check that the login has been disabled by executing the following query:
The *login_name* specifies the Azure AD principal, which is an Azure AD user, group, or application.
56
56
57
-
For more information, see [CREATE LOGIN (Transact-SQL)](/sql/t-sql/statements/create-login-transact-sql?view=azuresqldb-current&preserve-view=true). More information about the `WITH OBJECT_ID` clause is explained in [the section below](#azure-ad-logins-and-users-with-non-unique-display-names).
57
+
For more information, see [CREATE LOGIN (Transact-SQL)](/sql/t-sql/statements/create-login-transact-sql?view=azuresqldb-current&preserve-view=true).
58
58
59
59
### Create user syntax
60
60
61
61
The below T-SQL syntax is already available in SQL Database, and can be used for creating database-level Azure AD principals mapped to Azure AD logins in the virtual master database.
62
62
63
-
To create an Azure AD user from an Azure AD login, use the following syntax:
63
+
To create an Azure AD user from an Azure AD login, use the following syntax. Only the Azure AD admin can execute this command in the virtual master database.
64
64
65
65
```syntaxsql
66
66
CREATE USER user_name FROM LOGIN login_name
67
67
```
68
68
69
-
For more information, see [CREATE USER (Transact-SQL)](/sql/t-sql/statements/create-user-transact-sql). More information about the `WITH OBJECT_ID` clause is explained in [the section below](#azure-ad-logins-and-users-with-non-unique-display-names).
69
+
For more information, see [CREATE USER (Transact-SQL)](/sql/t-sql/statements/create-user-transact-sql).
70
70
71
71
### Disable or enable a login using ALTER LOGIN syntax
72
72
@@ -97,64 +97,6 @@ The Azure AD principal `login_name` won't be able to log into any user database
97
97
98
98
For a tutorial on how to grant these roles, see [Tutorial: Create and utilize Azure Active Directory server logins](authentication-azure-ad-logins-tutorial.md).
99
99
100
-
## Azure AD logins and users with non-unique display names
101
-
102
-
Using the display name of a service principal that isn't unique in Azure AD leads to errors when creating the login or user in Azure SQL. For example, if `myapp` isn't unique, you may run into the following error when executing the following query:
103
-
104
-
```sql
105
-
CREATE LOGIN [myapp] FROM EXTERNAL PROVIDER
106
-
```
107
-
108
-
```output
109
-
Msg 33131, Level 16, State 1, Line 4
110
-
Principal 'myapp' has a duplicate display name. Make the display name unique in Azure Active Directory and execute this statement again.
111
-
```
112
-
113
-
> [!NOTE]
114
-
> The same error would happen with `CREATE USER` with a non-unique name.
115
-
116
-
This happens because it is possible to create Azure AD resources with the same display names. For example, creating an [Azure AD application (service principal)](authentication-aad-service-principal.md) or Azure AD group with the same name. In this release, we're also introducing the ability to create logins and users using the **Object ID** of the Azure resource.
117
-
118
-
```sql
119
-
CREATE LOGIN login_name FROM EXTERNAL PROVIDER WITH OBJECT_ID ='objectid'
120
-
```
121
-
122
-
- To execute the above query, the specified Object ID must exist in Azure AD where the Azure SQL resource resides. Otherwise, the `CREATE` command will fail.
123
-
- Most non-unique display names in Azure AD are related to service principals. Group names can also be non-unique as well. All Azure AD user display names are unique.
124
-
125
-
With the T-SQL DDL extension to create logins or users with the Object ID, you can avoid error *33131* and also specify an alias for the login or user created with the Object ID. For example, the following will create a login `myapp4466e` using the application Object ID `4466e2f8-0fea-4c61-a470-xxxxxxxxxxxx`.
126
-
127
-
```sql
128
-
CREATE LOGIN [myapp4466e] FROM EXTERNAL PROVIDER
129
-
WITH OBJECT_ID='4466e2f8-0fea-4c61-a470-xxxxxxxxxxxx'
130
-
```
131
-
132
-
> [!TIP]
133
-
> If you're looking to create a contained database user using the OBJECT ID, the command would be:
134
-
>
135
-
> ```sql
136
-
> CREATE USER [myapp4466e] FROM EXTERNAL PROVIDER
137
-
> WITH OBJECT_ID='4466e2f8-0fea-4c61-a470-xxxxxxxxxxxx'
138
-
>```
139
-
140
-
For more information on obtaining the Object ID of a service principal, see [Service principal object](/azure/active-directory/develop/app-objects-and-service-principals#service-principal-object.)
141
-
142
-
### Identify the user created for the application
143
-
144
-
It's important to verify the Azure AD alias is tied to the correct application or group. To check that the user was created for the correct service principal (application) or Azure AD group:
145
-
146
-
1. Get the **Application ID** of the application, or **Object ID** of the Azure AD group from the user created in SQL Database by executing the following query:
147
-
148
-
```sql
149
-
SELECT CAST(sid as uniqueidentifier) AzureID fromsys.server_principalsWHERE NAME ='myapp4466e'
150
-
```
151
-
152
-
`AzureID` corresponds to the *Applicaiton ID* for the service principal or *Object ID* for the Azure AD group.
153
-
154
-
1. Go to the [Azure portal](https://portal.azure.com), and in your **Enterprise Application** or Azure AD group resource, check the **Application ID** or **Object ID** respectively. See if it matches the one obtained from the above query.
155
-
156
-
> [!NOTE]
157
-
> When creating a user from a service principal, the **Object ID** is required when using the `WITH OBJECT_ID` clause with the `CREATE` T-SQL statement. This is different from the **Application ID** that is returned when you are trying to verify the alias in Azure SQL. Using this verification process, you can identify the main owner of the SQL alias in Azure AD, and prevent possible mistakes when creating logins or users with an Object ID.
0 commit comments