Exemplo n.º 1
0
        /// <summary>
        /// Gets the canvas login url
        /// </summary>
        /// <param name="returnUrlPath">
        /// The return Url Path.
        /// </param>
        /// <param name="cancelUrlPath">
        /// The cancel Url Path.
        /// </param>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="loginParameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// Returns the login url.
        /// </returns>
        public Uri GetLoginUrl(string returnUrlPath, string cancelUrlPath, string state, IDictionary <string, object> loginParameters)
        {
            Contract.Ensures(Contract.Result <Uri>() != null);

            var oauth = new FacebookOAuthClient
            {
                AppId = _settings.AppId
            };

            var oauthJsonState = PrepareCanvasLoginUrlOAuthState(returnUrlPath, cancelUrlPath, state, loginParameters);

            var oauthState            = FacebookUtils.Base64UrlEncode(Encoding.UTF8.GetBytes(oauthJsonState.ToString()));
            var mergedLoginParameters = FacebookUtils.Merge(loginParameters, null);

            mergedLoginParameters["state"] = oauthState;

            var appPath = _httpRequest.ApplicationPath;

            if (appPath != "/")
            {
                appPath = string.Concat(appPath, "/");
            }

            string redirectRoot = RedirectPath;

            var uriBuilder = new UriBuilder(CurrentCanvasUrl)
            {
                Path  = string.Concat(appPath, redirectRoot),
                Query = string.Empty
            };

            oauth.RedirectUri = uriBuilder.Uri;

            var loginUrl = oauth.GetLoginUrl(mergedLoginParameters);

            return(loginUrl);
        }