示例#1
0
        /// <summary>
        /// Completes the authenticate user call.
        /// </summary>
        /// <param name="client">The MixRadio client.</param>
        /// <param name="clientSecret">The client secret obtained during app registration</param>
        /// <param name="result">The result received through LaunchActivatedEventArgs.</param>
        /// <param name="cancellationToken">The cancellation token to cancel operation</param>
        /// <returns>
        /// An AuthResultCode indicating the result
        /// </returns>
        /// <remarks>This method is for Windows Phone 8.1 use</remarks>
        public static async Task <AuthResultCode> CompleteAuthenticateUserAsync(this MusicClient client, string clientSecret, WebAuthenticationResult result, CancellationToken?cancellationToken = null)
        {
            if (result != null)
            {
                if (result.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    var    authResult = AuthResultCode.Unknown;
                    string code       = null;

                    OAuthResultParser.ParseQuerystringForCompletedFlags(result.ResponseData, out authResult, out code);
                    if (authResult == AuthResultCode.Success)
                    {
                        var authToken = await client.GetAuthenticationTokenAsync(clientSecret, code, cancellationToken);

                        if (authToken != null)
                        {
                            await StoreOAuthToken(authToken, client.ClientId, clientSecret, cancellationToken).ConfigureAwait(false);
                        }
                    }

                    return(authResult);
                }
            }

            return(AuthResultCode.Unknown);
        }
        /// <summary>
        /// Handles the Navigating event of the Browser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The event args instance containing the event data.</param>
        private void Browser_Navigating(object sender, NavigatingEventArgs e)
        {
            string host  = e.Uri.Host;
            string query = e.Uri.Query;

            if (!string.IsNullOrEmpty(host) && !string.IsNullOrEmpty(query))
            {
                Debug.WriteLine("Navigating host=" + host + " query=" + query);
                if (string.Compare(this._host, host, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    AuthResultCode result            = AuthResultCode.Unknown;
                    string         authorizationCode = null;

                    OAuthResultParser.ParseQuerystringForCompletedFlags(query, out result, out authorizationCode);
                    if (result != AuthResultCode.Unknown)
                    {
                        Debug.WriteLine(e.Uri);
                        if (result == AuthResultCode.Success)
                        {
                            this.AuthorizationCode = authorizationCode;
                        }

                        this.ResultCode = result;
                        e.Cancel        = true;
                        this._authWaiter.Set();
                    }
                }
            }
        }