public override async Task <AuthenticateRequestResult> AuthenticateRequestAsync(Activity activity, string authHeader, CancellationToken cancellationToken) { var claimsIdentity = await JwtTokenValidation_AuthenticateRequestAsync(activity, authHeader, _credentialFactory, _authConfiguration, _httpClient, cancellationToken).ConfigureAwait(false); var scope = SkillValidation.IsSkillClaim(claimsIdentity.Claims) ? JwtTokenValidation.GetAppIdFromClaims(claimsIdentity.Claims) : _toChannelFromBotOAuthScope; var callerId = await GenerateCallerIdAsync(_credentialFactory, claimsIdentity, cancellationToken).ConfigureAwait(false); var appId = BuiltinBotFrameworkAuthentication.GetAppId(claimsIdentity); var credentials = await _credentialFactory.CreateCredentialsAsync(appId, scope, _toChannelFromBotLoginUrl, _validateAuthority, cancellationToken).ConfigureAwait(false); return(new AuthenticateRequestResult { ClaimsIdentity = claimsIdentity, Credentials = credentials, Scope = scope, CallerId = callerId }); }
public override async Task <AuthenticateRequestResult> AuthenticateRequestAsync(Activity activity, string authHeader, CancellationToken cancellationToken) { var claimsIdentity = await JwtTokenValidation.AuthenticateRequest(activity, authHeader, new DelegatingCredentialProvider(_credentialFactory), GetChannelProvider(), _authConfiguration, _httpClient).ConfigureAwait(false); var scope = SkillValidation.IsSkillClaim(claimsIdentity.Claims) ? JwtTokenValidation.GetAppIdFromClaims(claimsIdentity.Claims) : _toChannelFromBotOAuthScope; var callerId = await GenerateCallerIdAsync(_credentialFactory, claimsIdentity, cancellationToken).ConfigureAwait(false); var appId = GetAppId(claimsIdentity); var credentials = await _credentialFactory.CreateCredentialsAsync(appId, scope, _loginEndpoint, true, cancellationToken).ConfigureAwait(false); return(new AuthenticateRequestResult { ClaimsIdentity = claimsIdentity, Credentials = credentials, Scope = scope, CallerId = callerId }); }
public override async Task <UserTokenClient> CreateUserTokenClientAsync(ClaimsIdentity claimsIdentity, CancellationToken cancellationToken) { var appId = BuiltinBotFrameworkAuthentication.GetAppId(claimsIdentity); var credentials = await _credentialFactory.CreateCredentialsAsync(appId, _toChannelFromBotOAuthScope, _toChannelFromBotLoginUrl, _validateAuthority, cancellationToken).ConfigureAwait(false); return(new UserTokenClientImpl(appId, credentials, _oAuthUrl, _httpClientFactory?.CreateClient(), _logger)); }
public override async Task <UserTokenClient> CreateUserTokenClientAsync(ClaimsIdentity claimsIdentity, CancellationToken cancellationToken) { var appId = GetAppId(claimsIdentity); var credentials = await _credentialFactory.CreateCredentialsAsync(appId, _toChannelFromBotOAuthScope, _loginEndpoint, true, cancellationToken).ConfigureAwait(false); return(new UserTokenClientImpl(appId, credentials, _oauthEndpoint, _httpClientFactory?.CreateClient(), _logger)); }
public override async Task <IConnectorClient> CreateAsync(string serviceUrl, string audience, CancellationToken cancellationToken) { // Use the credentials factory to create credentails specific to this particular cloud environment. var credentials = await _credentialFactory.CreateCredentialsAsync(_appId, audience ?? _toChannelFromBotOAuthScope, _loginEndpoint, _validateAuthority, cancellationToken).ConfigureAwait(false); // A new connector client for making calls against this serviceUrl using credentials derived from the current appId and the specified audience. return(new ConnectorClient(new Uri(serviceUrl), credentials, _httpClient, disposeHttpClient: _httpClient == null)); }
public override async Task <IConnectorClient> CreateAsync(string serviceUrl, string audience, CancellationToken cancellationToken) { // Use the credentials factory to create credentails specific to this particular cloud environment. var credentials = await _credentialFactory.CreateCredentialsAsync(_appId, audience ?? _toChannelFromBotOAuthScope, _loginEndpoint, _validateAuthority, cancellationToken).ConfigureAwait(false); // A new connector client for making calls against this serviceUrl using credentials derived from the current appId and the specified audience. #pragma warning disable CA2000 // Dispose objects before losing scope var httpClient = _httpClientFactory?.CreateClient() ?? new HttpClient(); ConnectorClient.AddDefaultRequestHeaders(httpClient); return(new ConnectorClient(new Uri(serviceUrl), credentials, httpClient, true)); #pragma warning restore CA2000 // Dispose objects before losing scope }
public async override Task <InvokeResponse <T> > PostActivityAsync <T>(string fromBotId, string toBotId, Uri toUrl, Uri serviceUrl, string conversationId, Activity activity, CancellationToken cancellationToken = default) { _ = fromBotId ?? throw new ArgumentNullException(nameof(fromBotId)); _ = toBotId ?? throw new ArgumentNullException(nameof(toBotId)); _ = toUrl ?? throw new ArgumentNullException(nameof(toUrl)); _ = serviceUrl ?? throw new ArgumentNullException(nameof(serviceUrl)); _ = conversationId ?? throw new ArgumentNullException(nameof(conversationId)); _ = activity ?? throw new ArgumentNullException(nameof(activity)); _logger.LogInformation($"post to skill '{toBotId}' at '{toUrl}'"); var credentials = await _credentialsFactory.CreateCredentialsAsync(fromBotId, toBotId, _loginEndpoint, true, cancellationToken).ConfigureAwait(false); // Clone the activity so we can modify it before sending without impacting the original object. var activityClone = JsonConvert.DeserializeObject <Activity>(JsonConvert.SerializeObject(activity)); // Apply the appropriate addressing to the newly created Activity. activityClone.RelatesTo = new ConversationReference { ServiceUrl = activityClone.ServiceUrl, ActivityId = activityClone.Id, ChannelId = activityClone.ChannelId, Locale = activityClone.Locale, Conversation = new ConversationAccount { Id = activityClone.Conversation.Id, Name = activityClone.Conversation.Name, ConversationType = activityClone.Conversation.ConversationType, AadObjectId = activityClone.Conversation.AadObjectId, IsGroup = activityClone.Conversation.IsGroup, Properties = activityClone.Conversation.Properties, Role = activityClone.Conversation.Role, TenantId = activityClone.Conversation.TenantId, } }; activityClone.Conversation.Id = conversationId; activityClone.ServiceUrl = serviceUrl.ToString(); activityClone.Recipient ??= new ChannelAccount(); activityClone.Recipient.Role = RoleTypes.Skill; // Create the HTTP request from the cloned Activity and send it to the Skill. using (var jsonContent = new StringContent(JsonConvert.SerializeObject(activityClone, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8, "application/json")) { using (var httpRequestMessage = new HttpRequestMessage()) { httpRequestMessage.Method = HttpMethod.Post; httpRequestMessage.RequestUri = toUrl; httpRequestMessage.Content = jsonContent; httpRequestMessage.Headers.Add(ConversationConstants.ConversationIdHttpHeaderName, conversationId); // Add the auth header to the HTTP request. await credentials.ProcessHttpRequestAsync(httpRequestMessage, cancellationToken).ConfigureAwait(false); using (var httpResponseMessage = await _httpClient.SendAsync(httpRequestMessage, cancellationToken).ConfigureAwait(false)) { var content = httpResponseMessage.Content != null ? await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false) : null; if (httpResponseMessage.IsSuccessStatusCode) { // On success assuming either JSON that can be deserialized to T or empty. return(new InvokeResponse <T> { Status = (int)httpResponseMessage.StatusCode, Body = content?.Length > 0 ? JsonConvert.DeserializeObject <T>(content) : default });