Read user information from Skype for Business Online with Azure Function App

Let’s imagine that we want to create Address Book SPFx Web Part in which we want to have option to find and show details of our coworkers.

If you want to build it from scratch, you could choose TextField and DetailsList from Office Fabric UI. First for search box and second for showing results as you could see above.

But let’s take a look behind-scene – how we could search users from Azure AD and how could we get some of their additional information.

The most simplistic way is to use Microsoft Graph API. If you want to read only few common user details from Graph, you could use only User.Read permission.

  "resource": "Microsoft Graph",
  "scope": "User.Read"

But many times this is not enough and you have to specify User.Read.All permission in package-solution.json file of your SPFx Web Part too.

  "resource": "Microsoft Graph",
  "scope": "User.Read.All"

From SharePoint Framework core version 1.4.1 you could use msGraphClientFactory from context of your Web Part and you could call API for users resource like this below:

this.props.msGraphClientFactory.getClient().then(async (client: MSGraphClient): Promise<void> => {
	client.api("users?" + (filterTextWthoSpaces.length > 0 ? "$filter=" + (this.props.showDisabledUsers ? "" : "accountEnabled eq true and ") + "startswith(displayName,'" + filterText + "') or ..." + "$select=id,displayName,mobilePhone,mail,jobTitle,department,companyName,businessPhones,streetAddress,postalCode,city,onPremisesDomainName").get().then((data:any) => {

	  return resolve(filteredPersonas);
	}).catch((error: any) => {
	  return resolve([]);
}).catch((error :any) => {
	return resolve([]);

But very early you could find out that you couldn’t filter all properties from Graph API and you couldn’t get all user properties.

One of this properties are for example properties from Skype for Business Online. There you could have internal number for each person in your organization inside of IPPhone property. So how could we now get all this additional user properties from Skype for Business Online?

Solution could be Azure Function App. We have to use PowerShell language support because you could connect to Skype for Business Online API only with PowerShell SkypeOnlineConnector module -> more about that in one of my previous post.

After that you could use it like this example below.

$secpasswd = ConvertTo-SecureString $env:SkypeForBusinessPassword -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($env:SkypeForBusinessUserName, $secpasswd)

Import-Module "D:\home\site\wwwroot\GetIPPhone\SkypeOnlineConnector\SkypeOnlineConnector.psd1"
$sfbSession = New-CsOnlineSession -Credential $credentials
Import-PSSession -Session $sfbSession -Name Get-CsOnlineUser

SkypeForBusinessPassword and SkypeForBusinessUserName are Application Settings properties of our Azure Function App.

As you could see in code above we could import only Get-CsOnlineUser function from our CsOnlineSession because of performance gain.

After that you could call that function with id of specific user which you get it from MS Graph. Response contains IPPhone property.

$userReturn = Get-CsOnlineUser $id -ErrorAction Stop
$currIPPhone = $userReturn.IPPhone

All that code you could pack into Azure Function with HTTP request trigger. Line of code below post response back.

$result = $returnV | ConvertTo-Json
Out-File -Encoding Ascii -FilePath $res -inputObject $result

You could cache IPPhone property for each user in Azure Data Storage Table from Azure Function App like example in one of my previous blog post.

Happy coding folks!

Gašper Rupnik


3 thoughts on “Read user information from Skype for Business Online with Azure Function App

Add yours

  1. Hi Gašper,

    Do you still have this example up and running?
    When following your procedure, I’m facing an error on the new-CsOnlineSession commandlet :

    2019-07-05T08:20:26.819 [Error] Executed ‘Functions.HttpTrigger1’ (Failed, Id=05c9d1e7-0270-4c56-86ac-45b18c5c66b1)
    Result: Failure
    Exception: Could not find WWW-Authenticate header in response
    Stack: at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
    at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
    Any idea why?




  2. Is this a working way in the current version of Azure Functions. I still have the issue that i cannot run the SkypeOnlineConnector with the same error

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by

Up ↑

%d bloggers like this: