예제 #1
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);
        }
예제 #2
0
        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.");

        }
        //authorization endpoint
        //https://login.live.com/oauth20_authorize.srf?client_id=000000004C181609&scope=bingads.manage&response_type=token&redirect_uri=https://login.live.com/oauth20_desktop.srf
        private static Authentication GetOAuthDesktopMobileImplicitGrant()
        {
            Uri urlContainsAccessToken = new Uri("https://login.live.com/oauth20_desktop.srf?lc=1033#access_token=EwBwAnhlBAAUxT83/QvqiAZEx5SuwyhZqHzk21oAAQByeu4TZtrHQXh6uMcQ4JXDbWzcJxVuVwl1RydCm19GuyJM7eAIYzuSgteCLEW%2bkQyFsM79mVPUiDKOLboD0IPEXvrAKRYFbJ7/gcNIZHWxWSfE5ua8Gn5/p%2bRB76rY6KTvxfRM3pKmQ5E698qZ%2b0c7iIE9mBZ%2b99kNEZGf%2bAZpUwwt/b60PEg8u9w9PyMFgCmZ867ls7xNRKswHuED5B6nBAtbHYaIGp0dXWsAF791CVTXlUuqSd34EqPoqzLfwWtF5sVmPOD0FzBBKZ8WGNSlouJH0kdHCLYLB35oxOD3A%2bEbe/eTU8OIR69s3hnjlluE1m0WJBdTlheobg8ZDTkDZgAACJBHdLDmP1gjQAGKO5duubr8mq2gXSZfhXgDdal3yBBfkHk9ASrEacXf59Y9YmMBOT7uJIEpSyB8T5R4evs3Mhew069aX6B3n5%2bK7MCfK4RHyjCLzDlCW/WKYfNlU2jWW6u4CZoahSbGd03uI5UtmmxHl/kMLWhe6QSxr26wrzmXDQoRRQC5TnGoF3R0gy7I2Cmh4Ucxqie/1eW0aPyJHA8nAWiv/dwaoSZc/bzjoIeI5nfizyy9zq3jo7xaVOLUhHVTRPXLRkV6H7XnKxnFVN6vkiwNRsnBl0nL480KqZ8kokMKE8/QqiyKmTW3CBWLJJmlLhmVLxKtMlDoQqST%2bQvv1igLaCsb/5VU7IQ/NFYcpg24O2C77hq6/8bpjdAnxw%2b2dEQzIkzqbc7BPMFAAIg13QhVZGBGFG8bF5S6vjmmrrPqvx/diWYiMlsB&token_type=bearer&expires_in=3600&scope=bingads.manage&user_id=38097d39a8aba1094d0e0fc7996e3bf5");
            var authentication = new OAuthDesktopMobileImplicitGrant(GlobalConfig.ClientId);
            authentication.ExtractAccessTokenFromUri(urlContainsAccessToken);
            CommonHelper.OutputMessage(string.Format("OAuthTokens.AccessToken = {0}", authentication.OAuthTokens.AccessToken));
            CommonHelper.OutputMessage(string.Format("OAuthTokens.AccessTokenExpiresInSeconds = {0}", authentication.OAuthTokens.AccessTokenExpiresInSeconds));
            CommonHelper.OutputMessage(string.Format("OAuthTokens.RefreshToken = {0}", authentication.OAuthTokens.RefreshToken));

            return authentication;
        }