• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-dotnet / 385929

08 Mar 2024 08:31PM UTC coverage: 78.19% (-0.2%) from 78.399%
385929

push

CI-PR build

web-flow
Support Sso for SharePoint bot ACEs (#6755)

* Support Sso for SharePoint bot ACEs

* Adding IStorage back in

* Adding support for QuickView SSO

26181 of 33484 relevant lines covered (78.19%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.57
/libraries/Microsoft.Bot.Builder/SharePoint/SharePointActivityHandler.cs
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
// Licensed under the MIT License.
3

4
using System;
5
using System.Collections.Generic;
6
using System.Net;
7
using System.Text;
8
using System.Threading;
9
using System.Threading.Tasks;
10
using Microsoft.Bot.Connector;
11
using Microsoft.Bot.Connector.Authentication;
12
using Microsoft.Bot.Schema;
13
using Microsoft.Bot.Schema.SharePoint;
14
using Microsoft.Bot.Schema.Teams;
15
using Newtonsoft.Json.Linq;
16

17
namespace Microsoft.Bot.Builder.SharePoint
18
{
19
    /// <summary>
20
    /// The SharePointActivityHandler is derived from ActivityHandler. It adds support for 
21
    /// the SharePoint specific events and interactions.
22
    /// </summary>
23
    public class SharePointActivityHandler : ActivityHandler
24
    {
25
        /// <summary>
26
        /// Safely casts an object to an object of type <typeparamref name="T"/> .
27
        /// </summary>
28
        /// <param name="value">The object to be casted.</param>
29
        /// <typeparam name="T">Template type.</typeparam>
30
        /// <returns>The object casted in the new type.</returns>
31
        internal static T SafeCast<T>(object value)
32
        {
33
            var obj = value as JObject;
1✔
34
            if (obj == null)
1✔
35
            {
36
                throw new InvokeResponseException(HttpStatusCode.BadRequest, $"expected type '{value.GetType().Name}'");
×
37
            }
38

39
            return obj.ToObject<T>();
1✔
40
        }
41

42
        /// <summary>
43
        /// Invoked when an invoke activity is received from the connector.
44
        /// Invoke activities can be used to communicate many different things.
45
        /// </summary>
46
        /// <param name="turnContext">A strongly-typed context object for this turn.</param>
47
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
48
        /// or threads to receive notice of cancellation.</param>
49
        /// <returns>A task that represents the work queued to execute.</returns>
50
        /// <remarks>
51
        /// Invoke activities communicate programmatic commands from a client or channel to a bot.
52
        /// The meaning of an invoke activity is defined by the <see cref="IInvokeActivity.Name"/> property,
53
        /// which is meaningful within the scope of a channel.
54
        /// </remarks>
55
        protected override async Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext<IInvokeActivity> turnContext, CancellationToken cancellationToken)
56
        {
57
            try
58
            {
59
                if (turnContext.Activity.Name == null)
1✔
60
                {
61
                    throw new NotSupportedException();
×
62
                }
63
                else
64
                {
65
                    switch (turnContext.Activity.Name)
1✔
66
                    {
67
                        case "cardExtension/getCardView":
68
                            return CreateInvokeResponse(await OnSharePointTaskGetCardViewAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));
1✔
69

70
                        case "cardExtension/getQuickView":
71
                            return CreateInvokeResponse(await OnSharePointTaskGetQuickViewAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));
1✔
72

73
                        case "cardExtension/getPropertyPaneConfiguration":
74
                            return CreateInvokeResponse(await OnSharePointTaskGetPropertyPaneConfigurationAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));
1✔
75

76
                        case "cardExtension/setPropertyPaneConfiguration":
77
                            BaseHandleActionResponse setPropPaneConfigResponse = await OnSharePointTaskSetPropertyPaneConfigurationAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false);
1✔
78
                            ValidateSetPropertyPaneConfigurationResponse(setPropPaneConfigResponse);
1✔
79
                            return CreateInvokeResponse(setPropPaneConfigResponse);
1✔
80

81
                        case "cardExtension/handleAction":
82
                            return CreateInvokeResponse(await OnSharePointTaskHandleActionAsync(turnContext, SafeCast<AceRequest>(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false));
1✔
83

84
                        case "cardExtension/token":
85
                            await OnSignInInvokeAsync(turnContext, cancellationToken).ConfigureAwait(false);
×
86
                            return CreateInvokeResponse();
×
87
                    }
88
                }
89
            }
×
90
            catch (InvokeResponseException e)
91
            {
92
                return e.CreateInvokeResponse();
×
93
            }
94

95
            return await base.OnInvokeActivityAsync(turnContext, cancellationToken).ConfigureAwait(false);
×
96
        }
1✔
97

98
        /// <summary>
99
        /// Override this in a derived class to provide logic for when a card view is fetched.
100
        /// </summary>
101
        /// <param name="turnContext">A strongly-typed context object for this turn.</param>
102
        /// <param name="aceRequest">The ACE invoke request value payload.</param>
103
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
104
        /// or threads to receive notice of cancellation.</param>
105
        /// <returns>A Card View Response for the request.</returns>
106
        protected virtual Task<CardViewResponse> OnSharePointTaskGetCardViewAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
107
        {
108
            throw new InvokeResponseException(HttpStatusCode.NotImplemented);
×
109
        }
110

111
        /// <summary>
112
        /// Override this in a derived class to provide logic for when a quick view is fetched.
113
        /// </summary>
114
        /// <param name="turnContext">A strongly-typed context object for this turn.</param>
115
        /// <param name="aceRequest">The ACE invoke request value payload.</param>
116
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
117
        /// or threads to receive notice of cancellation.</param>
118
        /// <returns>A Quick View Response for the request.</returns>
119
        protected virtual Task<QuickViewResponse> OnSharePointTaskGetQuickViewAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
120
        {
121
            throw new InvokeResponseException(HttpStatusCode.NotImplemented);
×
122
        }
123

124
        /// <summary>
125
        /// Override this in a derived class to provide logic for getting configuration pane properties.
126
        /// </summary>
127
        /// <param name="turnContext">A strongly-typed context object for this turn.</param>
128
        /// <param name="aceRequest">The ACE invoke request value payload.</param>
129
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
130
        /// or threads to receive notice of cancellation.</param>
131
        /// <returns>A Property Pane Configuration Response for the request.</returns>
132
        protected virtual Task<GetPropertyPaneConfigurationResponse> OnSharePointTaskGetPropertyPaneConfigurationAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
133
        {
134
            throw new InvokeResponseException(HttpStatusCode.NotImplemented);
×
135
        }
136

137
        /// <summary>
138
        /// Override this in a derived class to provide logic for setting configuration pane properties.
139
        /// </summary>
140
        /// <param name="turnContext">A strongly-typed context object for this turn.</param>
141
        /// <param name="aceRequest">The ACE invoke request value payload.</param>
142
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
143
        /// or threads to receive notice of cancellation.</param>
144
        /// <returns>Card view or no-op action response.</returns>
145
        /// <remarks>The handler will fail with 500 status code if the response is of type <see cref="QuickViewHandleActionResponse" />.</remarks>
146
        protected virtual Task<BaseHandleActionResponse> OnSharePointTaskSetPropertyPaneConfigurationAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
147
        {
148
            throw new InvokeResponseException(HttpStatusCode.NotImplemented);
×
149
        }
150

151
        /// <summary>
152
        /// Override this in a derived class to provide logic for handling ACE actions.
153
        /// </summary>
154
        /// <param name="turnContext">A strongly-typed context object for this turn.</param>
155
        /// <param name="aceRequest">The ACE invoke request value payload.</param>
156
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
157
        /// or threads to receive notice of cancellation.</param>
158
        /// <returns>A handle action response.</returns>
159
        protected virtual Task<BaseHandleActionResponse> OnSharePointTaskHandleActionAsync(ITurnContext<IInvokeActivity> turnContext, AceRequest aceRequest, CancellationToken cancellationToken)
160
        {
161
            throw new InvokeResponseException(HttpStatusCode.NotImplemented);
×
162
        }
163

164
        private void ValidateSetPropertyPaneConfigurationResponse(BaseHandleActionResponse response)
165
        {
166
            if (response is QuickViewHandleActionResponse)
1✔
167
            {
168
                throw new InvokeResponseException(HttpStatusCode.InternalServerError, "Response for SetPropertyPaneConfiguration action can't be of QuickView type.");
×
169
            }
170
        }
1✔
171
    }
172
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc