-
Notifications
You must be signed in to change notification settings - Fork 16
Feat: add signin/failure invoke handling #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3030e5d
Feat: add signin/failure invoke handling
cf46d70
Apply PR feedback
9a7c41f
Apply PR feedback
f80c939
Add example to graph sample
e919a9e
Update with list of failure codes
a8f95e9
Fix capitalization
8b083ce
Fix samples build
8276a84
Apply copilot feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Libraries/Microsoft.Teams.Api/Activities/Invokes/SignIn/FailureActivity.cs
This file contains hidden or 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,37 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| using Microsoft.Teams.Common; | ||
|
|
||
| namespace Microsoft.Teams.Api.Activities.Invokes; | ||
|
|
||
| public partial class Name : StringEnum | ||
| { | ||
| public partial class SignIn : StringEnum | ||
| { | ||
| public static readonly SignIn Failure = new("signin/failure"); | ||
| public bool IsFailure => Failure.Equals(Value); | ||
| } | ||
| } | ||
|
|
||
| public static partial class SignIn | ||
| { | ||
| /// <summary> | ||
| /// Represents a signin/failure invoke activity sent by Teams when SSO token exchange fails. | ||
| /// </summary> | ||
| public class FailureActivity() : SignInActivity(Name.SignIn.Failure) | ||
| { | ||
| /// <summary> | ||
| /// A value that is associated with the activity. | ||
| /// </summary> | ||
| [JsonPropertyName("value")] | ||
| [JsonPropertyOrder(32)] | ||
| public new required Api.SignIn.Failure Value | ||
| { | ||
| get => (Api.SignIn.Failure)base.Value!; | ||
| set => base.Value = value; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,26 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Teams.Api.SignIn; | ||
|
|
||
| /// <summary> | ||
| /// Sign-in failure information sent by Teams when SSO token exchange fails. | ||
| /// </summary> | ||
| public class Failure | ||
| { | ||
| /// <summary> | ||
| /// The error code for the sign-in failure (e.g., "resourcematchfailed"). | ||
| /// </summary> | ||
| [JsonPropertyName("code")] | ||
| [JsonPropertyOrder(0)] | ||
| public string? Code { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The error message for the sign-in failure. | ||
| /// </summary> | ||
| [JsonPropertyName("message")] | ||
| [JsonPropertyOrder(1)] | ||
| public string? Message { get; set; } | ||
| } |
124 changes: 124 additions & 0 deletions
124
Libraries/Microsoft.Teams.Apps/Activities/Invokes/SignIn/FailureActivity.cs
This file contains hidden or 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,124 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Teams.Api.Activities; | ||
| using Microsoft.Teams.Api.Activities.Invokes; | ||
| using Microsoft.Teams.Apps.Routing; | ||
|
|
||
| namespace Microsoft.Teams.Apps.Activities.Invokes; | ||
|
|
||
| /// <summary> | ||
| /// Attribute for handling signin/failure invoke activities sent when SSO token exchange fails. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Method, Inherited = true)] | ||
| public class FailureAttribute() : InvokeAttribute(Api.Activities.Invokes.Name.SignIn.Failure, typeof(SignIn.FailureActivity)) | ||
| { | ||
| public override object Coerce(IContext<IActivity> context) => context.ToActivityType<SignIn.FailureActivity>(); | ||
| } | ||
|
|
||
| public static partial class AppInvokeActivityExtensions | ||
| { | ||
| /// <summary> | ||
| /// Registers a handler for signin/failure invoke activities sent when SSO token exchange fails. | ||
| /// </summary> | ||
| public static App OnSignInFailure(this App app, Func<IContext<SignIn.FailureActivity>, Task> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.SignIn.Failure]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = async context => | ||
| { | ||
| await handler(context.ToActivityType<SignIn.FailureActivity>()); | ||
| return null; | ||
| }, | ||
| Selector = activity => activity is SignIn.FailureActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers a handler for signin/failure invoke activities sent when SSO token exchange fails. | ||
| /// </summary> | ||
| public static App OnSignInFailure(this App app, Func<IContext<SignIn.FailureActivity>, Task<object?>> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.SignIn.Failure]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = context => handler(context.ToActivityType<SignIn.FailureActivity>()), | ||
| Selector = activity => activity is SignIn.FailureActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers a handler for signin/failure invoke activities sent when SSO token exchange fails. | ||
| /// </summary> | ||
| public static App OnSignInFailure(this App app, Func<IContext<SignIn.FailureActivity>, Task<Response?>> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.SignIn.Failure]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = async context => await handler(context.ToActivityType<SignIn.FailureActivity>()), | ||
| Selector = activity => activity is SignIn.FailureActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers a handler for signin/failure invoke activities sent when SSO token exchange fails, with cancellation token support. | ||
| /// </summary> | ||
| public static App OnSignInFailure(this App app, Func<IContext<SignIn.FailureActivity>, CancellationToken, Task> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.SignIn.Failure]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = async context => | ||
| { | ||
| await handler(context.ToActivityType<SignIn.FailureActivity>(), context.CancellationToken); | ||
| return null; | ||
| }, | ||
| Selector = activity => activity is SignIn.FailureActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers a handler for signin/failure invoke activities sent when SSO token exchange fails, with cancellation token support. | ||
| /// </summary> | ||
| public static App OnSignInFailure(this App app, Func<IContext<SignIn.FailureActivity>, CancellationToken, Task<object?>> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.SignIn.Failure]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = context => handler(context.ToActivityType<SignIn.FailureActivity>(), context.CancellationToken), | ||
| Selector = activity => activity is SignIn.FailureActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers a handler for signin/failure invoke activities sent when SSO token exchange fails, with cancellation token support. | ||
| /// </summary> | ||
| public static App OnSignInFailure(this App app, Func<IContext<SignIn.FailureActivity>, CancellationToken, Task<Response?>> handler) | ||
| { | ||
| app.Router.Register(new Route() | ||
| { | ||
| Name = string.Join("/", [ActivityType.Invoke, Name.SignIn.Failure]), | ||
| Type = app.Status is null ? RouteType.System : RouteType.User, | ||
| Handler = async context => await handler(context.ToActivityType<SignIn.FailureActivity>(), context.CancellationToken), | ||
| Selector = activity => activity is SignIn.FailureActivity | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.