-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
56 changed files
with
2,309 additions
and
232 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// <copyright file="CCBotAdapter.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
// </copyright> | ||
|
||
namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Adapter | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Secrets; | ||
|
||
/// <summary> | ||
/// Bot framework http adapter instance. | ||
/// </summary> | ||
public class CCBotAdapter : CCBotAdapterBase | ||
{ | ||
private readonly ICertificateProvider certificateProvider; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CCBotAdapter"/> class. | ||
/// </summary> | ||
/// <param name="botFrameworkAuthentication">credential provider.</param> | ||
public CCBotAdapter( | ||
ICertificateProvider certificateProvider, | ||
BotFrameworkAuthentication botFrameworkAuthentication) | ||
: base(botFrameworkAuthentication) | ||
{ | ||
this.certificateProvider = certificateProvider; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override async Task CreateConversationUsingCertificateAsync(string channelId, string serviceUrl, AppCredentials appCredentials, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken) | ||
{ | ||
var cert = await this.certificateProvider.GetCertificateAsync(appCredentials.MicrosoftAppId); | ||
var options = new CertificateAppCredentialsOptions() | ||
{ | ||
AppId = appCredentials.MicrosoftAppId, | ||
ClientCertificate = cert, | ||
}; | ||
|
||
await this.CreateConversationAsync(appCredentials.MicrosoftAppId, channelId, serviceUrl, null/*audience*/, conversationParameters, callback, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override async Task CreateConversationUsingSecretAsync(string channelId, string serviceUrl, MicrosoftAppCredentials credentials, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken) | ||
{ | ||
await this.CreateConversationAsync(credentials.MicrosoftAppId, channelId, serviceUrl, null/*audience*/, conversationParameters, callback, cancellationToken); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Source/CompanyCommunicator.Common/Adapter/CCBotAdapterBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// <copyright file="CCBotAdapterBase.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
// </copyright> | ||
|
||
namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Adapter | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Logging; | ||
|
||
/// <summary> | ||
/// Bot Framework Http Adapter interface. | ||
/// </summary> | ||
public abstract class CCBotAdapterBase : CloudAdapter | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CCBotAdapterBase"/> class. | ||
/// </summary> | ||
/// <param name="botFrameworkAuthentication">Bot Framework Authentication.</param> | ||
/// <param name="logger">Logger</param> | ||
protected CCBotAdapterBase(BotFrameworkAuthentication botFrameworkAuthentication, ILogger logger = null) | ||
: base(botFrameworkAuthentication, logger) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a conversation using app secret on the specified channel. | ||
/// </summary> | ||
/// <param name="channelId">The ID for the channel.</param> | ||
/// <param name="serviceUrl">The channel's service URL endpoint.</param> | ||
/// <param name="credentials">The application credentials for the bot.</param> | ||
/// <param name="conversationParameters">The conversation information to use to create the conversation.</param> | ||
/// <param name="callback">The method to call for the resulting bot turn.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
/// <returns>A task that represents the work queued to execute.</returns> | ||
public abstract Task CreateConversationUsingSecretAsync(string channelId, string serviceUrl, MicrosoftAppCredentials credentials, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// Creates a conversation using app certificate on the specified channel. | ||
/// This method can be used to use certificates for authentication. | ||
/// </summary> | ||
/// <param name="channelId">The ID for the channel.</param> | ||
/// <param name="serviceUrl">The channel's service URL endpoint.</param> | ||
/// <param name="appCredentials">The application credentials for the bot.</param> | ||
/// <param name="conversationParameters">The conversation information to use to create the conversation.</param> | ||
/// <param name="callback">The method to call for the resulting bot turn.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
/// <returns>A task that represents the work queued to execute.</returns> | ||
public abstract Task CreateConversationUsingCertificateAsync(string channelId, string serviceUrl, AppCredentials appCredentials, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken); | ||
} | ||
} |
80 changes: 0 additions & 80 deletions
80
Source/CompanyCommunicator.Common/Adapter/CCBotFrameworkHttpAdapter.cs
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
Source/CompanyCommunicator.Common/Configuration/CommericalConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Configuration | ||
{ | ||
/// <summary> | ||
/// App configuration for commercial environment. | ||
/// </summary> | ||
public class CommericalConfiguration : IAppConfiguration | ||
{ | ||
private readonly string tenantId; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CommericalConfiguration"/> class. | ||
/// </summary> | ||
/// <param name="tenantId">Tenant id.</param> | ||
public CommericalConfiguration(string tenantId) | ||
{ | ||
this.tenantId = tenantId ?? throw new System.ArgumentNullException(nameof(tenantId)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string AzureAd_Instance => "https://login.microsoftonline.com"; | ||
|
||
/// <inheritdoc/> | ||
public string AzureAd_ValidIssuers => "https://login.microsoftonline.com/TENANT_ID/v2.0,https://sts.windows.net/TENANT_ID/"; | ||
|
||
/// <inheritdoc/> | ||
public string AuthorityUri => $"https://login.microsoftonline.com/{this.tenantId}"; | ||
|
||
/// <inheritdoc/> | ||
public string GraphBaseUrl => "https://graph.microsoft.com/v1.0"; | ||
|
||
/// <inheritdoc/> | ||
public string GraphDefaultScope => "https://graph.microsoft.com/.default"; | ||
|
||
/// <inheritdoc/> | ||
public string GraphUserReadScope => "https://graph.microsoft.com/User.Read openid profile"; | ||
|
||
/// <inheritdoc/> | ||
public string TeamsLicenseId => "57ff2da0-773e-42df-b2af-ffb7a2317929"; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Source/CompanyCommunicator.Common/Configuration/ConfigurationFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Configuration | ||
{ | ||
/// <summary> | ||
/// Configuration factory returns relevant configuration for a given environment. | ||
/// </summary> | ||
public class ConfigurationFactory | ||
{ | ||
private readonly string tenantId; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConfigurationFactory"/> class. | ||
/// </summary> | ||
/// <param name="tenantId">Tenant id.</param> | ||
public ConfigurationFactory(string tenantId) | ||
{ | ||
this.tenantId = tenantId ?? throw new System.ArgumentNullException(nameof(tenantId)); | ||
} | ||
|
||
/// <summary> | ||
/// Configuration factory returns relevant configuration for a given environment. | ||
/// </summary> | ||
/// <param name="env">Teams environment.</param> | ||
/// <returns>App configurstion.</returns> | ||
public IAppConfiguration GetAppConfiguration(TeamsEnvironment env) | ||
{ | ||
switch (env) | ||
{ | ||
case TeamsEnvironment.Commercial: | ||
case TeamsEnvironment.GCC: | ||
return new CommericalConfiguration(this.tenantId); | ||
case TeamsEnvironment.GCCH: | ||
return new GCCHConfiguration(this.tenantId); | ||
default: | ||
return new CommericalConfiguration(this.tenantId); | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Source/CompanyCommunicator.Common/Configuration/GCCHConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Configuration | ||
{ | ||
/// <summary> | ||
/// App configuration for GCCH environment. | ||
/// </summary> | ||
internal class GCCHConfiguration : IAppConfiguration | ||
{ | ||
private readonly string tenantId; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GCCHConfiguration"/> class. | ||
/// </summary> | ||
/// <param name="tenantId">TenantId.</param> | ||
public GCCHConfiguration(string tenantId) | ||
{ | ||
this.tenantId = tenantId ?? throw new System.ArgumentNullException(nameof(tenantId)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string AzureAd_Instance => "https://login.microsoftonline.us/"; | ||
|
||
/// <inheritdoc/> | ||
public string AzureAd_ValidIssuers => $"https://login.microsoftonline.us/{this.tenantId}/v2.0,https://sts.windows.net/{this.tenantId}/"; | ||
|
||
/// <inheritdoc/> | ||
public string AuthorityUri => $"https://login.microsoftonline.us/{this.tenantId}"; | ||
|
||
/// <inheritdoc/> | ||
public string GraphBaseUrl => "https://graph.microsoft.us/v1.0"; | ||
|
||
/// <inheritdoc/> | ||
public string GraphDefaultScope => "https://graph.microsoft.us/.default"; | ||
|
||
/// <inheritdoc/> | ||
public string GraphUserReadScope => "https://graph.microsoft.us/User.Read openid profile"; | ||
|
||
/// <inheritdoc/> | ||
public string TeamsLicenseId => "9953b155-8aef-4c56-92f3-72b0487fce41"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Source/CompanyCommunicator.Common/Configuration/IAppConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// <copyright file="IAppConfiguration.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
// </copyright> | ||
|
||
namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Configuration | ||
{ | ||
/// <summary> | ||
/// App configuration interface. | ||
/// </summary> | ||
public interface IAppConfiguration | ||
{ | ||
public string AzureAd_Instance { get; } | ||
|
||
public string AzureAd_ValidIssuers { get; } | ||
|
||
public string AuthorityUri { get; } | ||
|
||
public string GraphBaseUrl { get; } | ||
|
||
public string GraphDefaultScope { get; } | ||
|
||
public string GraphUserReadScope { get; } | ||
|
||
public string TeamsLicenseId { get; } | ||
} | ||
} |
Oops, something went wrong.