Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add AAD auth support for Azure SQL Database #7

Open
nzolotar opened this issue Jun 27, 2020 · 5 comments
Open

Please add AAD auth support for Azure SQL Database #7

nzolotar opened this issue Jun 27, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@nzolotar
Copy link

nzolotar commented Jun 27, 2020

I cant get it to work because you only accept connection as a string! And I need to get Azure token first and then establish a connection. Please advise if there any options. urgent project!

        private async Task<string> GetToken()
        {

            var ctx = new AuthenticationContext("https://login.microsoftonline.com/xxx");
            var result = await ctx.AcquireTokenAsync("https://database.windows.net/", new ClientCredential("xxx", "xxx"));
            return result.AccessToken;
        }

and then

using (var conn = new SqlConnection("Data Source=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;"))
            {
                conn.AccessToken = await GetToken();

                return await conn.QueryASync<T>(sql);
            }
@nzolotar nzolotar added the enhancement New feature or request label Jun 27, 2020
@TroyWitthoeft
Copy link

TroyWitthoeft commented Jul 20, 2020

I'm in need of this feature too! We're using DbUp with Azure SQL. Would love to use AAD or MSIs instead of having to worry about protecting sql credentials

@sungam3r has tersely demonstrated how to use Azure Integrated Security with DbUp.
Let's close this issue?

@nzolotar for reference, there is a method overload of SqlDatabase() that accepts boolean for azure support.
Example

    var upgrader =
        DeployChanges.To
            .SqlDatabase(connectionString,null,true)
            .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
            .LogToConsole()
            .Build();

Thanks,

  • Troy Witthoeft

@holtalanm
Copy link

holtalanm commented Feb 1, 2021

This does not work for Azure AD when on Azure Gov.

the url for getting the token that is hard-coded is incorrect here ("https://database.windows.net/"). Is there a way to make this configurable?

For the record, for Azure AD on Azure Gov, the url should be: "https://database.usgovcloudapi.net"

@sungam3r
Copy link
Member

My links from #7 point to nowhere... I don't remember what I wanted to show.

@droyad droyad transferred this issue from DbUp/DbUp Jan 30, 2024
@mcolebiltd
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

6 participants