예제 #1
0
파일: Program.cs 프로젝트: subanark/PowerUT
            public (bool success, DataSourceSetting) UserAAD(DataSource dataSource)
            {
                var oauthProvider = dataSource.GetOAuthProvider(new OAuthClientApplication("a672d62c-fc7b-4e81-a576-e60dc46e951d", "", "https://de-users-preview.sqlazurelabs.com/account/reply/"));
                var startLogin    = oauthProvider.StartLogin(activityId, "");

                (bool success, DataSourceSetting auth)result = (false, null);
                (Form window, WebBrowser authPage)           = AuthProvider(startLogin);
                using (window)
                    using (authPage)
                    {
                        Uri callbackUri     = null;
                        var pageNavListener = AuthPage_Navigated((uri) => { callbackUri = uri; });
                        WebBrowserNavigatedEventHandler AuthPage_Navigated(Action <Uri> redirectUri)
                        {
                            void Navigated(object sender, WebBrowserNavigatedEventArgs navEvent)
                            {
                                if (navEvent.Url.AbsoluteUri.StartsWith(startLogin.CallbackUri.AbsoluteUri, StringComparison.Ordinal))
                                {
                                    redirectUri(navEvent.Url);
                                    authPage.Navigated -= Navigated;
                                    window.Close();
                                }
                            };
                            return(Navigated);
                        }

                        authPage.Navigated += pageNavListener;
                        window.ShowDialog();
                        authPage.Navigated -= pageNavListener;
                        if (callbackUri != null)
                        {
                            var creds = oauthProvider.FinishLogin(startLogin.SerializedContext, callbackUri, activityId);
                            result = (true, DataSourceSetting.CreateOAuth2Credential(creds.AccessToken));
                        }
                        else
                        {
                            result = (false, null);
                        }
                    }
                return(result);
            }