Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Enable companion app scenario for Linked Accounts web app #1529

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ public HomeController(ICredentialProvider credentialProvider, IConfiguration con
this.Configuration = configuration;
}

public IActionResult Index()
public IActionResult Index(bool companionApp = false)
{
return this.View();
return RedirectToAction("LinkedAccounts", new { companionApp = companionApp });
}

/// <summary>
/// Initialisation work for the LinkedAccounts feature.
/// Initialisation work for the Linked Accounts feature.
/// </summary>
/// <param name="companionApp">Flag used to show a sample deep link to a companion application.</param>
/// <returns>IActionResult.</returns>
public async Task<IActionResult> LinkedAccounts()
public async Task<IActionResult> LinkedAccounts(bool companionApp = false)
{
this.ViewData["Message"] = "Your application description page.";

Expand All @@ -47,22 +48,22 @@ public async Task<IActionResult> LinkedAccounts()
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"{endpoint}/tokens/generate");
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", secret);

// In order to avoid magic code prompts we need to set a TrustedOrigin, therefore requests using the token can be validated
// as coming from this web-site and protecting against scenarios where a URL is shared with someone else
string trustedOrigin = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

request.Content = new StringContent(JsonConvert.SerializeObject(new { TrustedOrigins = new string[] { trustedOrigin } }),
request.Content = new StringContent(
JsonConvert.SerializeObject(new { TrustedOrigins = new string[] { trustedOrigin } }),
Encoding.UTF8,
"application/json");

var response = await client.SendAsync(request);
string token = String.Empty;
string token = string.Empty;

if (response.IsSuccessStatusCode)
{
// We have a Directline Token

var body = await response.Content.ReadAsStringAsync();
token = JsonConvert.DeserializeObject<DirectLineToken>(body).token;

Expand All @@ -77,7 +78,8 @@ public async Task<IActionResult> LinkedAccounts()
UserId = userId,
DirectLineToken = token,
Endpoint = endpoint,
Status = tokenStatuses
Status = tokenStatuses,
CompanionApp = companionApp,
});
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class LinkedAccountRepository : ILinkedAccountRepository
private const string TokenServiceUrl = "https://api.botframework.com";

/// <summary>
/// Enumerate the Linked Account status for a given UserId and return status information
/// Enumerate the Linked Account status for a given UserId and return status information.
/// </summary>
/// <param name="userId"></param>
/// <param name="credentialProvider"></param>
/// <returns></returns>
/// <param name="userId">User Id value.</param>
/// <param name="credentialProvider">The credential provider value.</param>
/// <returns>Array of TokenStatus.</returns>
public async Task<TokenStatus[]> GetTokenStatusAsync(string userId, ICredentialProvider credentialProvider)
{
// The BotFramework Adapter, Bot ApplicationID and Bot Secret is required to access the Token APIs
Expand All @@ -49,13 +49,13 @@ public async Task<TokenStatus[]> GetTokenStatusAsync(string userId, ICredentialP
}

/// <summary>
/// Retrieve a signin link for a user based on the Connection Name. This is then used for the user to click and authenticate, generating a token returned back to the Token store
/// Retrieve a signin link for a user based on the Connection Name. This is then used for the user to click and authenticate, generating a token returned back to the Token store.
/// </summary>
/// <param name="userId"></param>
/// <param name="credentialProvider"></param>
/// <param name="connectionName"></param>
/// <param name="finalRedirect"></param>
/// <returns></returns>
/// <param name="userId">The user id value.</param>
/// <param name="credentialProvider">The credential provider value.</param>
/// <param name="connectionName">The connection name value.</param>
/// <param name="finalRedirect">The final redirect value.</param>
/// <returns>Sign in link string value.</returns>
public async Task<string> GetSignInLinkAsync(string userId, ICredentialProvider credentialProvider, string connectionName, string finalRedirect)
{
// The BotFramework Adapter, Bot ApplicationID and Bot Secret is required to access the Token APIs
Expand Down Expand Up @@ -86,12 +86,12 @@ public async Task<string> GetSignInLinkAsync(string userId, ICredentialProvider
}

/// <summary>
/// Sign a given user out of a previously linked account
/// Sign a given user out of a previously linked account.
/// </summary>
/// <param name="userId"></param>
/// <param name="credentialProvider"></param>
/// <param name="connectionName"></param>
/// <returns></returns>
/// <param name="userId">The user id value.</param>
/// <param name="credentialProvider">The credential provider value.</param>
/// <param name="connectionName">The connection name value.</param>
/// <returns>Task.</returns>
public async Task SignOutAsync(string userId, ICredentialProvider credentialProvider, string connectionName = null)
{
// The BotFramework Adapter, Bot ApplicationID and Bot Secret is required to access the Token APIs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright(c) Microsoft Corporation.All rights reserved.
// Licensed under the MIT License.



namespace LinkedAccounts.Web.Controllers
{
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public class LinkedAccountsViewModel
public string DirectLineToken { get; set; }

public string Endpoint { get; set; }

public bool CompanionApp { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,24 @@ else
<div class="content-row">
<div class="content-title">Linked Accounts</div>
<div class="main-text main-text-p1">
The authentication providers listed below are the same providers you have enabled on your bot.

You may need to use a different user id in the Web Chat than what is displayed here.
You can update the values and select "Update User ID" to update what is stored in session.
The authentication providers listed below are those enabled on the Virtual Assistant.

If you need to use a different User Id for your client, you can update it's value and select <b>Update User Id</b> to update what is stored in session.
</div>
<div class="linkedAccount-displayName">
User ID:
@using (Html.BeginForm("ChangeUserId", "Home", FormMethod.Post))
{

@Html.TextBoxFor(model => model.UserId, new { style = "width:300px;" })
<button type="submit">Update User ID</button>
<button onclick="copyUserId()">Copy User ID</button>
<button type="submit">Update</button>
<button onclick="copyUserId()">Copy</button>
if (Model.CompanionApp)
{
<button onclick="window.open('microsoft://virtualassistant/user/@Model.UserId','_blank')" type="button">
Complete and return to app
</button>
}
@Html.ActionLink("Sign Out All", "SignOutAll", "Home", null, new { @class = "button" })
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ button {
}

.main-text-p1 {
padding-top: 48px;
padding-bottom: 28px;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.