Exemplo n.º 1
0
        private async Task LogIn(IDialogContext context, IMessageActivity msg, string resourceId)
        {
            try
            {
                string token = await context.GetAccessToken(resourceId);

                if (string.IsNullOrEmpty(token))
                {
                    if (msg.Text != null &&
                        CancellationWords.GetCancellationWords().Contains(msg.Text.ToUpper()))
                    {
                        context.Done(string.Empty);
                    }
                    else
                    {
                        var resumptionCookie = new ResumptionCookie(msg);

                        var authenticationUrl = await AzureActiveDirectoryHelper.GetAuthUrlAsync(resumptionCookie, resourceId);

                        await context.PostAsync($"You must be authenticated before you can proceed. Please, click [here]({authenticationUrl}) to log into your account.");

                        context.Wait(this.MessageReceivedAsync);
                    }
                }
                else
                {
                    context.Done(string.Empty);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        private async Task LogIn(IDialogContext context, Message msg)
        {
            try
            {
                string token = await context.GetAccessToken();

                if (string.IsNullOrEmpty(token))
                {
                    var resumptionCookie = new ResumptionCookie(msg);

                    var authenticationUrl = await AzureActiveDirectoryHelper.GetAuthUrlAsync(resumptionCookie);



                    await context.PostAsync($"You must be authenticated before you can proceed. Please, click [here]({authenticationUrl}) to log into your account.");

                    context.Wait(this.MessageReceivedAsync);
                }
                else
                {
                    context.Done(string.Empty);
                }
            }catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        private async Task LogIn(IDialogContext context, IMessageActivity msg, string[] scopes)
        {
            try
            {
                string token = await context.GetAccessToken(scopes);

                if (string.IsNullOrEmpty(token))
                {
                    if (msg.Text != null &&
                        CancellationWords.GetCancellationWords().Contains(msg.Text.ToUpper()))
                    {
                        context.Done(string.Empty);
                    }
                    else
                    {
                        var resumptionCookie = new ResumptionCookie(msg);

                        var authenticationUrl = await AzureActiveDirectoryHelper.GetAuthUrlAsync(resumptionCookie, scopes);

                        if (msg.ChannelId == "skype")
                        {
                            IMessageActivity response = context.MakeMessage();
                            response.Recipient = msg.From;
                            response.Type      = "message";

                            response.Attachments = new List <Attachment>();
                            List <CardAction> cardButtons = new List <CardAction>();
                            CardAction        plButton    = new CardAction()
                            {
                                Value = authenticationUrl,
                                Type  = "signin",
                                Title = "Authentication Required"
                            };

                            cardButtons.Add(plButton);
                            SigninCard plCard = new SigninCard(this.prompt, new List <CardAction>()
                            {
                                plButton
                            });
                            Attachment plAttachment = plCard.ToAttachment();
                            response.Attachments.Add(plAttachment);
                            await context.PostAsync(response);
                        }
                        else
                        {
                            await context.PostAsync(this.prompt + "[Click here](" + authenticationUrl + ")");
                        }
                        context.Wait(this.MessageReceivedAsync);
                    }
                }
                else
                {
                    context.Done(string.Empty);
                }
            }catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Checks if we are able to get an access token. If not, we prompt for a login
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual async Task CheckForLogin(IDialogContext context, IMessageActivity msg)
        {
            try
            {
                string token;
                if (resourceId != null)
                {
                    token = await context.GetAccessToken(resourceId);
                }
                else
                {
                    token = await context.GetAccessToken(scopes);
                }

                if (string.IsNullOrEmpty(token))
                {
                    if (msg.Text != null &&
                        CancellationWords.GetCancellationWords().Contains(msg.Text.ToUpper()))
                    {
                        context.Done(string.Empty);
                    }
                    else
                    {
                        var resumptionCookie = new ResumptionCookie(msg);

                        string authenticationUrl;
                        if (resourceId != null)
                        {
                            authenticationUrl = await AzureActiveDirectoryHelper.GetAuthUrlAsync(resumptionCookie, resourceId);
                        }
                        else
                        {
                            authenticationUrl = await AzureActiveDirectoryHelper.GetAuthUrlAsync(resumptionCookie, scopes);
                        }

                        await PromptToLogin(context, msg, authenticationUrl);

                        context.Wait(this.MessageReceivedAsync);
                    }
                }
                else
                {
                    context.Done(string.Empty);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }