/// <summary>
        /// Ensures that your application has authorization to manage a Bing Ads account.
        /// Requests authorization in a browser window.
        /// </summary>
        /// <returns>Returns an instance of OAuthDesktopMobileImplicitGrant when the authorization
        /// request task completes. </returns>
        public static async Task <OAuthDesktopMobileImplicitGrant> AuthorizeDesktopMobileImplicitGrant()
        {
            var auth = new OAuthDesktopMobileImplicitGrant(Settings.Default["ClientId"].ToString());

            await AuthorizeImplicitlyInBrowser(auth);

            return(auth);
        }
示例#2
0
        private static async Task AuthorizeImplicitlyInBrowser(OAuthDesktopMobileImplicitGrant auth)
        {
            var browserWindow = new BrowserWindow(auth.GetAuthorizationEndpoint(), auth.RedirectionUri.AbsolutePath);

            browserWindow.Show();

            var redirectUri = await browserWindow.GetRedirectUri();

            auth.ExtractAccessTokenFromUri(redirectUri);
        }
        private static async Task AuthorizeImplicitlyInBrowser(OAuthDesktopMobileImplicitGrant authentication)
        {
            var browserWindow = new BrowserWindow(authentication.GetAuthorizationEndpoint(), authentication.RedirectionUri.AbsolutePath);

            browserWindow.Show();

            var redirectUri = await browserWindow.GetRedirectUri();

            authentication.ExtractAccessTokenFromUri(redirectUri);

            if (authentication.State != ClientState)
            {
                throw new HttpRequestException("The OAuth response state does not match the client request state.");
            }
        }