-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C#] feat: Implement
GetTokenOrStartSignInAsync
method public inter…
…face (#987) ## Linked issues closes: #894 (issue number) ## Details - Rename `TeamsAIAuthException` to `AuthException` - Rename `TeamsAIAuthReason` to `AuthExceptionReason` - Implement helper methods in `AuthUtilities` - Implement `GetTokenOrStartSignInAsync`. - Add `IsUserSignedIn` to `IAuthentication` interface - this is needed so it can be called in the `Application` class. - Make `AuthenticationManager._default` private property public `Default`. ## Attestation Checklist - [x] My code follows the style guidelines of this project - I have checked for/fixed spelling, linting, and other errors - I have commented my code for clarity - I have made corresponding changes to the documentation (we use [TypeDoc](https://typedoc.org/) to document our code) - My changes generate no new warnings - I have added tests that validates my changes, and provides sufficient test coverage. I have tested with: - Local testing - E2E testing in Teams - New and existing unit tests pass locally with my changes
- Loading branch information
Showing
16 changed files
with
358 additions
and
69 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/Application/Authentication/AuthUtilitiesTest.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,90 @@ | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Teams.AI.State; | ||
using Microsoft.Teams.AI.Tests.TestUtils; | ||
|
||
namespace Microsoft.Teams.AI.Tests.Application.Authentication | ||
{ | ||
public class AuthUtilitiesTest | ||
{ | ||
[Fact] | ||
public async void Test_SetTokenInState() | ||
{ | ||
// Arrange | ||
TurnContext context = TurnStateConfig.CreateConfiguredTurnContext(); | ||
TurnState state = await TurnStateConfig.GetTurnStateWithConversationStateAsync(context); | ||
string settingName = "settingName"; | ||
string token = "token"; | ||
|
||
// Act | ||
AuthUtilities.SetTokenInState(state, settingName, token); | ||
|
||
// Assert | ||
Assert.True(state.Temp.AuthTokens.ContainsKey(settingName)); | ||
} | ||
|
||
[Fact] | ||
public async void Test_DeleteTokenFromState() | ||
{ | ||
// Arrange | ||
TurnContext context = TurnStateConfig.CreateConfiguredTurnContext(); | ||
TurnState state = await TurnStateConfig.GetTurnStateWithConversationStateAsync(context); | ||
string settingName = "settingName"; | ||
string token = "token"; | ||
|
||
// Act | ||
state.Temp.AuthTokens[settingName] = token; | ||
AuthUtilities.DeleteTokenFromState(state, settingName); | ||
|
||
// Assert | ||
Assert.False(state.Temp.AuthTokens.ContainsKey(settingName)); | ||
} | ||
|
||
[Fact] | ||
public async void Test_UserInSignInFlow() | ||
{ | ||
// Arrange | ||
TurnContext context = TurnStateConfig.CreateConfiguredTurnContext(); | ||
TurnState state = await TurnStateConfig.GetTurnStateWithConversationStateAsync(context); | ||
string settingName = "settingName"; | ||
|
||
// Act | ||
state.User.Set(AuthUtilities.IS_SIGNED_IN_KEY, settingName); | ||
string? response = AuthUtilities.UserInSignInFlow(state); | ||
|
||
// Assert | ||
Assert.True(response == settingName); | ||
|
||
} | ||
|
||
[Fact] | ||
public async void Test_SetUserInSignInFlow() | ||
{ | ||
// Arrange | ||
TurnContext context = TurnStateConfig.CreateConfiguredTurnContext(); | ||
TurnState state = await TurnStateConfig.GetTurnStateWithConversationStateAsync(context); | ||
string settingName = "settingName"; | ||
|
||
// Act | ||
AuthUtilities.SetUserInSignInFlow(state, settingName); | ||
|
||
// Assert | ||
Assert.True(state.User.Get<string>(AuthUtilities.IS_SIGNED_IN_KEY) == settingName); | ||
} | ||
|
||
[Fact] | ||
public async void Test_DeleteUserInSignInFlow() | ||
{ | ||
// Arrange | ||
TurnContext context = TurnStateConfig.CreateConfiguredTurnContext(); | ||
TurnState state = await TurnStateConfig.GetTurnStateWithConversationStateAsync(context); | ||
string settingName = "settingName"; | ||
|
||
// Act | ||
state.User.Set(AuthUtilities.IS_SIGNED_IN_KEY, settingName); | ||
AuthUtilities.DeleteUserInSignInFlow(state); | ||
|
||
// Assert | ||
Assert.False(state.User.ContainsKey(AuthUtilities.IS_SIGNED_IN_KEY)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.