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 async Task <ContactEntity> GetContactEntityAsync(int contactId, Tenant tenant) { // maybe the tenant canceled their subscription... // make sure the tenant is running (not off-line or in backup or maintenance mode) var tenantStatus = GetTenantStatus(tenant); if (tenantStatus.IsRunning) { var sysUserInfo = GetSystemUserInfo(); var sysUserTicket = await GetSystemUserTicket(sysUserInfo); var config = new WebApiOptions(tenant.WebApiUrl); config.Authorization = new AuthorizationSystemUserTicket(sysUserInfo, sysUserTicket); //config.LanguageCode = "en"; //config.CultureCode = "en"; //config.TimeZone = "UTC"; var contactAgent = new ContactAgent(config); return(await contactAgent.GetContactEntityAsync(contactId)); } return(null); }