Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Sunday, February 11, 2018

Azure Active Directory App Only Authentication with PnP PowerShell

Why do we need app only authentication? Well, if you want to execute some code without the permissions of a user or without an authentication token of a user, your only option is App Only authentication. In simple terms, if you want to execute a task by a daemon, App Only authentication is your best option.

This post is the 1st post of a series of blog posts, in building a solution which executes some PowerShell code in an Azure Function to manipulate some data which resides in SharePoint Online.

This blog post focuses on creating an Azure Active Directory App and granting permissions to the App to communicate with SharePoint Online.

In your Office 365 Admin Center, select Azure Active Directory. On the left side menu, select Azure Active Directory. Select App Registration and click on "+ New application registration". Provide a meaningful name for the "Name", select Application type as "Web app/API" and a Sign-on URL. The Sign-on URL can be any URL and I will discuss in a future post where it will be used. Also, this can be changed later.

Once the App is created, Azure will provide an Unique Application ID for the App. 
Next, select Settings, Required permissions and Add.
Then you can select the APIs you need to access to. Let's select Office 365 SharePoint Online.
You need to configure the following permissions.

  • Have full control of all site collections (Application permissions)

The required permission level depends on your requirements of the final solution. I'm planning to create new sites within site collections, so I've granted the above permissions. Remember, it's an "Application Permission". Application permissions granted to the applications when running as App Only.
Next, click the Grant Permission button on the required permissions tab. This will provide non-tenant admin users access to the application.
Now we need to create a self signed certificate (or a commercial certificate) and update the Azure AD Application manifest.

Use the below PowerShell script to create a self signed certificate. Make sure you have installed OfficeDev PnP PowerShell.
1
2
3
4
5
6
7
8
9
$certroot = 'C:\Site Creator'
$certname = "IntelAi-Cert-1"
$password = ConvertTo-SecureString "P@$$w0rd" -AsPlainText -Force
$startdate = Get-Date
$enddate = $startdate.AddYears(4)
makecert.exe -r -pe -n "CN=$certname" -b ($startdate.ToString("MM/dd/yyyy")) -e ($enddate.ToString("MM/dd/yyyy")) -ss my -len 2048
$cert = Get-ChildItem Cert:\CurrentUser\My | ? {$_.Subject -eq "CN=$certname"}
Export-Certificate -Type CERT -FilePath "$certroot\$certname.cer" -Cert $cert -Force
Export-PfxCertificate -FilePath "$certroot\$certname.pfx" -Cert $cert -Password $password -Force

Now execute the below script. It will copy a string to your clipboard.
Get-PnPAzureADManifestKeyCredentials -CertPath 'C:\Site Creator\IntelAi-Cert-1.cer' | clip

The copied string would look similar to the below. We need to add this string in to the manifest file of the Azure AD Application. (I've trimmed the value property)
"keyCredentials": [
 {
  "customKeyIdentifier": "5lca+kziogw7T6MB4kUrxseK5m8=",
  "keyId": "84153f1a-90b7-4802-b99a-bb75d4f9a35b",
  "type": "AsymmetricX509Cert",
  "usage": "Verify",
  "value": "MIIDAjCCAe6gAwIBAgIQkawCJU0cWYxH8RamKNuqqTAJBgUrDgMCHQUAMBkx
 }
],

Select you application within App registrations under Azure Active Directory. Replace the "keyCredentials":[], section, as shown below.

Now we can test whether the application has enough permission to connect to the SharePoint Online site. For the ClientID, you need to provide the Application ID of the application you have created.
1
2
3
4
$password = ConvertTo-SecureString "P@$$w0rd" -AsPlainText -Force
Connect-PnPOnline -Url https://intelai.sharepoint.com/ -ClientId 0c01f61e-ba27-4ae7-ab19-174884a949fc -CertificatePath 'C:\Site Creator\IntelAi-Cert-1.pfx' -CertificatePassword $password -Tenant intelai.onmicrosoft.com
$myWeb = Get-PnPWeb
$myWeb.Title


Saturday, May 20, 2017

SharePoint Saturday - Colombo 2017

I'm honoured to be a part of the SharePoint Saturday - Colombo Chapter by being an organiser and a speaker. You can find more details of the sessions and the speakers in http://www.spsevents.org/city/Colombo/Colombo2017/home


Speakers and the team who was behind the seen to make it great success.

Speakers...

and that's me hosting the session; "The Serverless Nirvana"

All attendees...

and how can we forget the selfie...

thanks again for everybody who made it a great success. Till #SPSaturday #SPSColombo

Friday, April 7, 2017

Mount an Azure File Share using PowerShell

I'll start this blog post with the exact use-case I went through. I was deploying a SharePoint environment in the Cloud. The requirement was to deploy a staging environment and the production environment where each environment has 7 servers deployed with SharePoint. To make the deployments process easier, I had to download all the necessary binaries in to one location which can be accessible from all servers. This includes all the other supporting tools. So basically a shared drive for all machines.

The good thing with Azure file Share is, its not limited to Cloud when sharing or accessing. Once the storage account is created which includes a file share, it can be accessed from machines/VMs in cloud as well as machines in on-premises.

I named my file share as fscommon. Well, as a practice I used to as a prefix for all the resources I create.
Prior mounting the file share, you need to make sure you copy your storage account key.

You can select one of the keys given by azure. You can replace the existing keys by regenerating new keys. Below PowerShell script can be used to attached your Azure File Share to your machine. Make sure to replace the storage account key, storage account name, Drive letter and the share name with your own values.

 $acctKey = ConvertTo-SecureString -String "<storage-account-key>" -AsPlainText -Force  
 $credential = New-Object System.Management.Automation.PSCredential -ArgumentList "Azure\<storage-account-name>", $acctKey  
 New-PSDrive -Name <desired-drive-letter> -PSProvider FileSystem -Root "\\<storage-account-name>.file.core.windows.net\<share-name>" -Credential $credential  


But shared drive will be mounted till you restart your machine. If you need to mount the drive permanently (till you unmount), use the -persist parameter with the New-SPDrive cmdlet.

Happy days :)

Saturday, March 11, 2017

Automate Office 365 PowerShell in Azure

One of my clients who's using Office 365 had a requirement to execute a PowerShell script on a predefined schedule. This can be achieved in many different ways. You can even automate a script using Windows scheduler. But what I'm going to talk about is a, how to automate a script using Azure Automation. As a prerequisite You must have a Azure.

Log in to your Azure tenant and create a Azure Automation Account.


Create an account.

Next step is to select the necessary PowerShell Module. My PowerShell script was based on SharePointPnPPowerShellOnline. You can simply go to the Modules section, search for the relevant module.

and import.

As you are executing the script remotely, you have to store a users credentials. Hopefully not as plain text in the script. :) Select the Credentials and add the username and the password.


Next is to add your script by selecting Runbooks and adding one.

Place your script in the editor. Also make sure to add your stored credentials as shown in the below screen. You can create a variable from the credentials and pass it to your command.

 $credentials = Get-AutomationPSCredential -Name 'Quicksilver'  

Save & Publish. Next go to the Schedule and create a new schedule for your Runbook.
Happy days!! :)

Saturday, February 11, 2017

Add a new user to an existing Azure Subscription

As the title says, this is very simple task. But understand the structure and providing proper access the correct subscription is sometimes a tricky task.

Let me explain my scenario. I'm using a single Microsoft account to log in to Azure Portal where I manage multiple Azure Subscriptions. I wanted to add a user or grant permissions to another users to one of Azure Subscriptions where he can manage resources.


So, the first thing did was, select the subscription and select Access control (IAM). In the image you can see I've already given permission to 2 users the necessary permission.

Click on Add where you will see a blade with the all available roles, scope of where the users permission will be set to and where you can select/search your user.

If your use is already added to your AD, the name will be displayed in the dropdown. If not you can still search for the user and provide the access rights. In my scenario, its just the Contributer access I wanted to provide.
With  from Cloud.

Monday, October 3, 2016

Collab365 – Azure Notification Hub

I’ll be speaking at the largest online conference for SharePoint, Office 365 and Azure which is Collab365 Global Conference 2016. It’ll take place on 19th to 20th October with 121 online sessions.

600x200_speakerbadge_GC_thumb[3]

Session title: Azure Notification Hub

Session overview:
Do you have a need to send notifications to thousands or millions of users at once who use different devices on different platforms? Azure notification hub is the best answer. Azure Notification Hubs provide an easy-to-use, multiplatform, scaled-out push infrastructure that enables you to send mobile push notifications to any mobile platform. With Notification Hubs you can easily send cross-platform, personalized push notifications, abstracting the details of the different platform notification systems (PNS). With a single API call, you can target individual users or entire audience segments containing millions of users, across all their devices. In this session I will cover the basics of Azure Notification Hub, configuration, building an application to send and receive notification and customizing your notifications with different templates.

What you will learn:

  • Basics of Azure Notification Hub
  • Need of Windows App Developer account
  • Configuring Notification Hub
  • Send and receive notifications
  • Customize notifications with Payload templates

For registration link.

Monday, May 2, 2016

Azure Roadshow 2016

Another busy day for the MVPs and the techies. It’s the Azure Roadshow time for the year 2016. A day full of technical sessions. This is in parallel to to the Global Azure Boot Camp.

group-photo

dsc_0999

dsc_0893

dsc_0824

dsc_0834

dsc_0948

It’s always a pleasure to engage in community activities and share the knowledge with the techies. Smile

Friday, January 15, 2016

Deploy on-premises database to Azure SQL database

This is simple step by step guide to deploy your on-premises (or even cloud) Microsoft SQL database to Azure SQL database service with data.  Simply, this is a data migration to Azure SQL.

You have to make sure you have an Azure tenant with an active subscription to proceed with the next few steps. I have downloaded and installed AdventureWorks2014 database in my own machine for the demonstration.

One more prerequisite, you need to have a SQL database server in Azure. Your server name should look be similar to yourservername.database.windows.net.

Open Microsoft SQL Server Management Studio, right click on the database, select “Tasks” and select “Deploy Database to Microsoft Azure SQL Database…”
1

After the introduction screen, you will be asked to set the deployment settings. There you must set the server connection, the new database name and a temporary location for the bacpac file.
3

Once you click on the Connect, to connect to the Azure database server, you will be asked to enter the credentials.
4

You will then be asked to add a firewall rule where you have to sign in and provide access permissions to your ip address (or subnet) to access the azure database server.
5
6

Once the above steps are done, you will be allowed to set the pricing tier for the server. This is bit of a tricky thing as there are DTUs for each tier. The resources and power of each service tier and performance level for Microsoft's Azure SQL cloud databases are expressed in terms of Database Throughput Units (DTUs). The available resources will vary based on the DTUs. So till we complete the data migration, it’s better to stay within the standard tier.
7

Providing the necessary information, you can proceed with the data migration.
9

Once completed, we can see the DTU consumption and you can use your preferred tool to connect to Azure SQL Database.
10

Sunday, September 7, 2014

Building Enterprise Applications on Azure

I was invited by Redynamics Sri Lanka to conduct a technical session on “Building Enterprise Application on Azure” for Microsoft FSI sector.