/// <inheritdoc/> protected override async Task <AppCredentials> BuildCredentialsAsync(string appId, string oAuthScope = null) { appId = appId ?? throw new ArgumentNullException(nameof(appId)); if (!this.certificateProvider.IsCertificateAuthenticationEnabled()) { return(await base.BuildCredentialsAsync(appId, oAuthScope)); } var cert = await this.certificateProvider.GetCertificateAsync(appId); var options = new CertificateAppCredentialsOptions() { AppId = appId, ClientCertificate = cert, OauthScope = oAuthScope, }; var certificateAppCredentials = new CertificateAppCredentials(options) as AppCredentials; return(certificateAppCredentials); }
/// <inheritdoc/> public async Task <AppCredentials> GetBotAppCredentialsAsync() { try { var response = await this.certificateClient.DownloadCertificateAsync(this.appSettings.BotCertificateName); var clientCredentials = new CertificateAppCredentials(response.Value, this.appSettings.BotAppId); return(clientCredentials); } catch (InvalidDataException exception) { this.logger.LogError(exception, $"Certificate not found. Cert name: {this.appSettings.BotCertificateName} "); } catch (RequestFailedException exception) { this.logger.LogError(exception, $"Failed to fetch certificate. ErrorCode: {exception.ErrorCode} Cert name: {this.appSettings.BotCertificateName}."); } catch (Exception exception) { this.logger.LogError(exception, $"Failed to fetch certificate. Cert name: {this.appSettings.BotCertificateName}."); } throw new QBotException(HttpStatusCode.InternalServerError, ErrorCode.Unknown, "Failed to get bot app certificate."); }