Cookie CSS

Saturday, March 18, 2017

Skype for Business Trusted Application API - Part III

Over the last 2 blog posts I have outlined how to create the Azure AD, and SFB prerequisites to create a TAP Application.  This week we will use those settings to create a simple test application.  We will base it on the sample code example called Remote Advisor (spelled wrong) here.

Before we begin making changes let's make sure you have the latest nuget packages, and the prerelease option turned on.  As of today pre-release v4 is the current version.



We will begin by opening the sample code and looking at the App.config file.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.13.7.964" newVersion="3.13.7.964" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.13.7.964" newVersion="3.13.7.964" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<appSettings>
<add key="AAD_ClientId" value="{your aad application id get from application registration portal}" />
<add key="AAD_ClientSecret" value="{your aad application client secret get from application registration portal}" />
<add key="ApplicationEndpointId" value="{your application sip uri registered on tenant admin remote powershell, like sip:endpoint1@contoso.com}" />
</appSettings>
</configuration>
view raw App.config hosted with ❤ by GitHub


Here we will need to fill out 3 things;

1.  AAD_ClientId - This is your application ID found in the Azure AD portal.
2.  AAD_ClientSecret - This is the client secret which was created and visible right after creating the app.  If you lost it, you can make a new one in AAD under keys.
3.  ApplicationEndPointID - This is the endpoint you created in the SFB online powershell last week.

Once you have those updated go ahead and save the file.  Now we will open the program.cs.


using Microsoft.SfB.PlatformService.SDK.ClientModel;
using Microsoft.SfB.PlatformService.SDK.Common;
using QuickSamplesCommon;
using System;
using System.Threading.Tasks;
/// <summary>
/// Simple sampel on remote advisor scenario:
/// 1. Schedule an adhoc meeting with SkypeforBusiness
/// 2. And get anon token of that adhoc meeting for webSDK or AppSDK anon user to join the meeting
/// </summary>
namespace RemoteAdvisorSample
{ class Program
{
static void Main(string[] args)
{
RemoteAdvisorSample sample = new RemoteAdvisorSample();
try
{
sample.Run().Wait();
}
catch (AggregateException ex)
{
Console.WriteLine("Exception hit:" + ex.GetBaseException().ToString());
}
}
}
internal class RemoteAdvisorSample
{
public async Task Run()
{
ConsoleLogger logger = new ConsoleLogger();
logger.HttpRequestResponseNeedsToBeLogged = true;//Set to true if you want to log all http request and responses
//Prepare platform
ClientPlatformSettings platformSettings = new ClientPlatformSettings(QuickSamplesConfig.AAD_ClientSecret, Guid.Parse(QuickSamplesConfig.AAD_ClientId));
var platform = new ClientPlatform(platformSettings, logger);
//Prepare endpoint
var eventChannel = new FakeEventChannel();
var endpointSettings = new ApplicationEndpointSettings(new SipUri(QuickSamplesConfig.ApplicationEndpointId));
ApplicationEndpoint applicationEndpoint = new ApplicationEndpoint(platform, endpointSettings, eventChannel);
var loggingContext = new LoggingContext(Guid.NewGuid());
await applicationEndpoint.InitializeAsync(loggingContext).ConfigureAwait(false);
await applicationEndpoint.InitializeApplicationAsync(loggingContext).ConfigureAwait(false);
//Schedule meeting
var input = new AdhocMeetingCreationInput(Guid.NewGuid().ToString("N") + "testMeeting");
var adhocMeeting = await applicationEndpoint.Application.CreateAdhocMeetingAsync(loggingContext, input).ConfigureAwait(false);
logger.Information("ad hoc meeting uri : " + adhocMeeting.OnlineMeetingUri);
logger.Information("ad hoc meeting join url : " + adhocMeeting.JoinUrl);
//Get anon join token
IAnonymousApplicationToken anonToken = await applicationEndpoint.Application.GetAnonApplicationTokenForMeetingAsync(
loggingContext,
adhocMeeting.JoinUrl,
"https://contoso.com;https://litware.com;http://www.microsoftstore.com/store/msusa/en_US/home", //Fill your own web site, For allow cross domain using
Guid.NewGuid().ToString() //Should be unique everytime
).ConfigureAwait(false);
logger.Information("Get anon token : " + anonToken.AuthToken);
logger.Information("Get discover url for web SDK : " + anonToken.AnonymousApplicationsDiscoverUri.ToString());
Console.ForegroundColor = ConsoleColor.Green;
logger.Information("RemoteAdvisor sample completed successfully!");
Console.ResetColor();
}
}
}
view raw program.cs hosted with ❤ by GitHub


Things you will need to update here are pretty simple to find.

Go to line 60, and change the allowed urls to include your own.  Now build and run the sample.  You should see various lines of output to indicate if the program worked, or an exception detailing why it didn't

A working program should show you tokens along the way as well as your meeting uri like this;



There you have it, you have successfully created a program that has authenticated using the TAP api, and created a meeting.

Doug Routledge, C# Lync, Skype for Business, SQL, Exchange, UC, 
Full Stack Developer  BridgeOC Bridge Operator Console
Twitter - @droutledge @ndbridge










No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.