public async T.Task OnGetAsync()
        {
            if (SearchId > 0)
            {
                var authenticationInfo = HttpContext.AuthenticateAsync()?.Result;
                if (authenticationInfo != null)
                {
                    // could use "User.Claims", but still need AuthInfo to access Tokens...

                    var webApiUrl      = authenticationInfo.Principal.Claims.Where(c => c.Type.Contains("webapi", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                    var clientSettings = _superOfficeOptions.Get(SuperOfficeAuthenticationDefaults.AuthenticationScheme);
                    var callbackUri    = $"{this.Request.Scheme}://{this.Request.Host}{clientSettings.CallbackPath}";

                    var authorization = new AuthorizationAccessToken(
                        authenticationInfo.Properties.GetTokenValue(Constants.OAuth.AccessToken),
                        authenticationInfo.Properties.GetTokenValue(Constants.OAuth.IdToken),
                        authenticationInfo.Properties.GetTokenValue(Constants.OAuth.RefreshToken),
                        clientSettings.ClientId,
                        clientSettings.ClientSecret,
                        callbackUri,
                        GetEnvironment(clientSettings.Environment)
                        );

                    var config = new WebApiOptions(webApiUrl.Value, authorization);

                    ContactAgent ca = new ContactAgent(config);
                    ContactEntity = await ca.GetContactEntityAsync(SearchId);
                }
            }
        }
        private void ValidateConnection()
        {
            if (this._authinfo.TimeObtained.AddSeconds(this._authinfo.ExpiresIn) < DateTime.Now.AddSeconds(-10))
            {
                string requestUri = Constants.PODIOAPI_BASEURL + "/oauth/token";
                Dictionary<string, string> _requestbody = new Dictionary<string, string>() {
                    {"grant_type","refresh_token"},
                    {"client_id",clientId},
                    {"client_secret",clientSecret},
                    {"refresh_token",_authinfo.RefreshToken}
                };

                this._authinfo = PodioRestHelper.Request<AuthorizationAccessToken>(requestUri, _requestbody, PodioRestHelper.RequestMethod.POST).Data;
                this._authinfo.TimeObtained = DateTime.Now; // mark the date and time obtained
            }
        }
示例#3
0
        private void ValidateConnection()
        {
            if (this._authinfo.TimeObtained.AddSeconds(this._authinfo.ExpiresIn) < DateTime.Now.AddSeconds(-10))
            {
                string requestUri = Constants.PODIOAPI_BASEURL + "/oauth/token";
                Dictionary <string, string> _requestbody = new Dictionary <string, string>()
                {
                    { "grant_type", "refresh_token" },
                    { "client_id", clientId },
                    { "client_secret", clientSecret },
                    { "refresh_token", _authinfo.RefreshToken }
                };

                this._authinfo = PodioRestHelper.Request <AuthorizationAccessToken>(requestUri, _requestbody, PodioRestHelper.RequestMethod.POST).Data;
                this._authinfo.TimeObtained = DateTime.Now; // mark the date and time obtained
            }
        }
    private bool PostLinkedIn()
    {
        string requestCode = Session[LinkedInCodeSessionKey].ToString();

        if (requestCode == null)
        {
            Session[MessageKey] = txtFeedContent.Text.Trim();
            //Session[TitleKey] = txtTitle.Text.Trim();

            var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
            var api    = new LinkedInApi(config);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress | AuthorizationScope.WriteShare | AuthorizationScope.ReadWriteCompanyPage;
            var state = Guid.NewGuid().ToString();
            var url   = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);

            Response.Redirect(url.AbsoluteUri, false);
        }
        else
        {
            int linkedInCompanyID = int.Parse(LinkedInCompanyID);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            try
            {
                string message = txtFeedContent.Text.Trim();

                var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
                // get the APIs client
                var api = new LinkedInApi(config);
                AuthorizationAccessToken userToken = api.OAuth2.GetAccessToken(requestCode, redirectUrl);

                if (userToken != null)
                {
                    string   acessToken           = userToken.AccessToken;
                    DateTime authorizationDateUTC = userToken.AuthorizationDateUtc;
                    int?     expiresIn            = userToken.ExpiresIn;

                    AccessTokenController accessTokenController = new AccessTokenController();
                    int addUpdateResult = accessTokenController.AddLinkedInAccessToken(acessToken, authorizationDateUTC, expiresIn);
                }

                UserAuthorization user = new UserAuthorization(userToken.AccessToken);

                PostShareResult postShareResult = api.Companies.Share(
                    user,
                    linkedInCompanyID, new PostShare()
                {
                    Visibility = new Visibility()
                    {
                        Code = "anyone"
                    },
                    Comment = message
                });

                string resultID = hdnSelectedMessageID.Value;
                SocialFeedController feedController = new SocialFeedController();
                UserChoiceInfo       userChoiceInfo = feedController.ConvertToUserChoice(postShareResult.Location, postShareResult.UpdateKey, postShareResult.UpdateUrl, message, resultID);

                int output = feedController.SaveUserChoice(userChoiceInfo);

                if (output == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }

        return(false);
    }
示例#5
0
 /// <summary>
 /// Go use the static constructor
 /// </summary>
 
 public Client(AuthorizationAccessToken authInfo, string clientId, string clientSecret)
 {
     this.clientId = clientId;
     this.clientSecret = clientSecret;
     this._authinfo = authInfo;
 }
示例#6
0
        /// <summary>
        /// Go use the static constructor
        /// </summary>

        public Client(AuthorizationAccessToken authInfo, string clientId, string clientSecret)
        {
            this.clientId     = clientId;
            this.clientSecret = clientSecret;
            this._authinfo    = authInfo;
        }