示例#1
0
        /// <summary>
        /// Authenticates a user to enable the user data APIs.
        /// </summary>
        /// <param name="startUri">The auth uri.</param>
        /// <param name="browser">The browser control to use to drive authentication.</param>
        /// <param name="oauthRedirectUri">The OAuth completed URI.</param>
        /// <param name="cancellationToken">The optional cancellation token.</param>
        /// <returns>
        /// An async task
        /// </returns>
        public async Task <Response <AuthResultCode> > AuthenticateUserAsync(Uri startUri, WebBrowser browser, string oauthRedirectUri, CancellationToken?cancellationToken = null)
        {
            if (this._browserController == null)
            {
                this._browserController = new OAuthBrowserController();
            }

            CancellationToken token = cancellationToken ?? CancellationToken.None;

            await Task.Run(() => this._browserController.DriveAuthProcess(browser, startUri, oauthRedirectUri, token), token);

            return(await this.ConvertAuthPermissionParamsAndFinalise(this._browserController.ResultCode != AuthResultCode.Cancelled, token));
        }
示例#2
0
        /// <summary>
        /// Continues the authenticate user flow by extracting results from the WP8-specific
        /// auth method and moving on to the final common step.
        /// </summary>
        /// <param name="taskCompleted">if set to <c>true</c> oauth task completed.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// Whether the token was retrieved
        /// </returns>
        internal async Task <Response <AuthResultCode> > ConvertAuthPermissionParamsAndFinalise(bool taskCompleted, CancellationToken?cancellationToken)
        {
            if (taskCompleted)
            {
                // Grab the results and kill the browser controller
                string         authorizationCode = this._browserController.AuthorizationCode;
                AuthResultCode resultCode        = this._browserController.ResultCode;
                this._browserController = null;

                // Move on to obtain a token
                return(await this.ObtainToken(authorizationCode, null, resultCode));
            }
            else
            {
                return(new Response <AuthResultCode>(null, new OperationCanceledException(), null, Guid.Empty));
            }
        }
示例#3
0
        /// <summary>
        /// Authenticates a user to enable the user data APIs.
        /// </summary>
        /// <param name="secureBaseApiUri">The secure base API URI.</param>
        /// <param name="scopes">The scopes requested.</param>
        /// <param name="browser">The browser control to use to drive authentication.</param>
        /// <param name="cancellationToken">The optional cancellation token.</param>
        /// <returns>
        /// An async task
        /// </returns>
        public async Task <Response <AuthResultCode> > AuthenticateUserAsync(string secureBaseApiUri, Scope scopes, WebBrowser browser, CancellationToken?cancellationToken = null)
        {
            this._secureBaseApiUri = secureBaseApiUri;

            Uri startUri = this.ConstructAuthorizeUri(scopes);

            if (this._browserController == null)
            {
                this._browserController = new OAuthBrowserController();
            }

            CancellationToken token = (cancellationToken != null && cancellationToken.HasValue) ? cancellationToken.Value : CancellationToken.None;

            await Task.Run(() => { this._browserController.DriveAuthProcess(browser, startUri, token); }, token);

            return(await this.ConvertAuthPermissionParamsAndFinalise(this._browserController.ResultCode != AuthResultCode.Cancelled, token));
        }
        /// <summary>
        /// Authenticates a user to enable the user data APIs.
        /// </summary>
        /// <param name="secureBaseApiUri">The secure base API URI.</param>
        /// <param name="scopes">The scopes requested.</param>
        /// <param name="browser">The browser control to use to drive authentication.</param>
        /// <param name="cancellationToken">The optional cancellation token.</param>
        /// <returns>
        /// An async task
        /// </returns>
        public async Task<Response<AuthResultCode>> AuthenticateUserAsync(string secureBaseApiUri, Scope scopes, WebBrowser browser, CancellationToken? cancellationToken = null)
        {
            this._secureBaseApiUri = secureBaseApiUri;
            
            Uri startUri = this.ConstructAuthorizeUri(scopes);

            if (this._browserController == null)
            {
                this._browserController = new OAuthBrowserController();
            }

            CancellationToken token = (cancellationToken != null && cancellationToken.HasValue) ? cancellationToken.Value : CancellationToken.None;

            await Task.Run(() => { this._browserController.DriveAuthProcess(browser, startUri, token); }, token);
            return await this.ConvertAuthPermissionParamsAndFinalise(this._browserController.ResultCode != AuthResultCode.Cancelled, token);
        }
        /// <summary>
        /// Continues the authenticate user flow by extracting results from the WP8-specific
        /// auth method and moving on to the final common step.
        /// </summary>
        /// <param name="taskCompleted">if set to <c>true</c> oauth task completed.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// Whether the token was retrieved
        /// </returns>
        internal async Task<Response<AuthResultCode>> ConvertAuthPermissionParamsAndFinalise(bool taskCompleted, CancellationToken? cancellationToken)
        {
            if (taskCompleted)
            {
                // Grab the results and kill the browser controller
                string authorizationCode = this._browserController.AuthorizationCode;
                AuthResultCode resultCode = this._browserController.ResultCode;
                this._browserController = null;

                // Move on to obtain a token
                return await this.ObtainToken(authorizationCode, null, resultCode);
            }
            else
            {
                return new Response<AuthResultCode>(null, new OperationCanceledException(), null, Guid.Empty);
            }
        }