/// <summary> /// Completes the authorization process. Access tokens and list of administrated companies are retrived and set to control that opened the dialog. /// </summary> private void CompleteAuthorization() { LinkedInAccessToken token; try { token = LinkedInHelper.CompleteAuthorization(TokenManager); } catch (Exception ex) { LogAndShowError("LinkedInCompanyAccessToken", "AUTH_COMPLETE", ex); return; } finally { SessionHelper.Remove(TokenManagerStoreKey); } List <LinkedInCompany> companies; try { companies = LinkedInHelper.GetUserCompanies((string)Parameters["ApiKey"], (string)Parameters["ApiSecret"], token.AccessToken, token.AccessTokenSecret); } catch (Exception ex) { LogAndShowError("LinkedInCompanyAccessToken", "GET_COMPANIES", ex); return; } string formattedExpiration = token.Expiration.HasValue ? TimeZoneHelper.ConvertToUserTimeZone(token.Expiration.Value, true, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite) : String.Empty; JavaScriptSerializer sr = new JavaScriptSerializer(); string json = sr.Serialize( new { accessToken = token.AccessToken, accessTokenSecret = token.AccessTokenSecret, tokenExpiration = token.Expiration.HasValue ? token.Expiration.Value.ToString("g", CultureInfo.InvariantCulture) : String.Empty, tokenExpirationString = formattedExpiration, tokenAppId = Parameters["AppInfoId"], companies } ); // Set retrieved access token to the opener window string script = String.Format(@" if(wopener.linkedInCompanyControl && wopener.linkedInCompanyControl['{0}']) {{ wopener.linkedInCompanyControl['{0}'].setData({1}); }} CloseDialog();", Parameters["ClientID"], json); ScriptHelper.RegisterStartupScript(Page, typeof(string), "TokenScript", script, true); }