Thursday, February 1, 2018

Generate & Replace an expiring client secret in a SharePoint Add-in


I have created a provider hosted app for SharePoint. It got expired due to validity of secrete because usually client secret validity is one year. Now the app started throwing exception to me i.e. ""Invalid JWT token. Could not resolve issuer token."

I did couple of research on it & found the solution from site "".

I have made some changes in this script to make little bit easier to use .

Here is the script :

#Actual Article

#Get help from :
#PS> Save-Module -Name MSOnline -Path <path>
#PS> Install-Module -Name MSOnline

#Get app details
$clientID = “<<YourClientIdGuidHere>>”
Write-Host "-------------------------------------------------`n" -ForegroundColor Yellow
Write-Host "Get the list of Apps :`n" -ForegroundColor Yellow
Get-MsolServicePrincipal -AppPrincipalId $clientID
#Get-MsolServicePrincipalCredential -AppPrincipalId $clientID -ReturnKeyValues $false | Where-Object { ($_.Type -ne “Other”) -and ($_.Type -ne “Asymmetric”) }

$clientKeys=Get-MsolServicePrincipalCredential -AppPrincipalId $clientID -ReturnKeyValues $false | Where-Object { ($_.Type -ne “Other”) -and ($_.Type -ne “Asymmetric”) }

Write-Host "=========================== END : Get the list of Apps ===========================`n" -ForegroundColor Green

# Get Keys from app

Get-MsolServicePrincipal -AppPrincipalId $clientID
$keys = Get-MsolServicePrincipalCredential -AppPrincipalId $clientID -ReturnKeyValues $true
Write-Host "-------------------------------------------------`n" -ForegroundColor Yellow
Write-Host "Showing the list of keys for the App :`n" -ForegroundColor Yellow

Remove-MsolServicePrincipalCredential -KeyIds @($key1," $key2"," $key3") -AppPrincipalId $clientId

Write-Host "=========================== END : Showing the list of keys for the App ===========================`n" -ForegroundColor Green

#Create new screte for the app
Write-Host "`n-------------------------------------------------`n" -ForegroundColor Yellow
Write-Host "Create new secret for the app :`n" -ForegroundColor Yellow

$bytes = New-Object Byte[] 32
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$newClientSecret = [System.Convert]::ToBase64String($bytes)

Write-Host "New client secret is : ($newClientSecret) `n" -ForegroundColor Red
$dtStart = [System.DateTime]::Now
$dtEnd = $dtStart.AddYears(3)
New-MsolServicePrincipalCredential -AppPrincipalId $clientID -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
New-MsolServicePrincipalCredential -AppPrincipalId $clientID -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
New-MsolServicePrincipalCredential -AppPrincipalId $clientID -Type Password -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd

Write-Host "New client secret is : ($newClientSecret) `n" -ForegroundColor Red

Write-Host "=========================== END : Create new secret for the app ===========================`n" -ForegroundColor Green

Wednesday, December 20, 2017

Create Private / Public CDN in SharePoint Online

Here are some command which can help you to create your own CDN :

# Connect to your tenant
Connect-SPOService -Url

# Check the current status of CDN capability - by default disabled
Get-SPOTenantCdnEnabled -CdnType Public
Get-SPOTenantCdnEnabled -CdnType Private

# Enable CDN using default settings - -NoDefaultOrigins as optional parameter
Set-SPOTenantCdnEnabled -CdnType Public -NoDefaultOrigins
Set-SPOTenantCdnEnabled -CdnType Private -NoDefaultOrigins

# Get CDN policies
Get-SPOTenantCdnPolicies -CdnType Public
Get-SPOTenantCdnPolicies -CdnType Private

# Add CDN origin
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl sites/cdn/cdn
Add-SPOTenantCdnOrigin -CdnType Private -OriginUrl sites/pub35/assets

# Get CDN origin
Get-SPOTenantCdnOrigins -CdnType Public
Get-SPOTenantCdnOrigins -CdnType Private

# Public CDN Url, when configured<tenant host name>/sites/sites/library

# Remove CDN origin
Remove-SPOTenantCdnOrigin -CdnType Public -OriginUrl sites/cdn/cdn
Remove-SPOTenantCdnOrigin -CdnType Private -OriginUrl sites/pub35/assets

# Disable CDN using default settings
Set-SPOTenantCdnEnabled -CdnType Public -Enable $false
Set-SPOTenantCdnEnabled -CdnType Private -Enable $false

Wednesday, October 4, 2017

How to move MS CRM 2013 database from one domain to another?

I wanted to move my MS CRM related organization database from one domain to another domain. I did research on it and did it. It is quite easy. Just follow these steps:

  • Install MS CRM 2013
  • Install Rollups for MS CRM 2013
  • First create all users which you have in old domain for MS CRM.
  • There has to be one user enable with System Administrator role in your old CRM.
  • Now just import your organization database into MS CRM with use of Deployment Manager of MS CRM 2013.
  • It will ask you to setup some information i.e. Organization display name, Unique Name, Currency etc., Please setup these information.
  • Then in next step, you have to map users. You can map users with following methods: 
    • Automatic mapping
    • Manually mapping
    • With XML file
  • Here you need to map at least one System Administrator from MS CRM DB. Here is one point which need to take care is, current user has to be System Admin in this case.

If you still facing any issue, Please feel free to ask me.

Tuesday, September 19, 2017

How to set My Start Page in Office 365?

Office 365 has given a way to set start page for current user. You can set it by using a few steps.

  • Login with url
  • Go to Office 365 settings
  • Now on the My Account setting page , Click on the Start Page.
  • You will be able to see more options & you can select as you want :

  • Here I am selecting SharePoint for me & you can select what you want & hit Save button & its done.

Tuesday, July 18, 2017

SharePoint Framework with the extension

I tried to create SharePoint Framework with the extension provided by SharePoint PnP. It is very easy to create a SharePoint Framework Web Part in Visual Studio.
Developer need to first fulfill the Pr-requisites
After installation of these pre-requisites , You will be ready to create new Web Part with SharePoint Framework. Here is simple steps to create a small web part:
Open Visual Studio 2015 / 2017 & Create new project. Here you need to go to the SharePoint templates category and then select SPFx Web Part Project.

You must provide solution name & Project Name. This solution name will be shown in next dialog box. Now hit OK.
Now one new form will be popup. Here you have to select Framework, Put Component Name, Component Description and at last a check box .

Here we have option “none, react, knockout “. You can choose any of these .By default Framework will be none & you can use any JavaScript framework later on.
At last you have to just hit “Generate” button. It will take a while to create new project with the Web Part with SharePoint Framework. After creating the project, it will also show you the log file.

Now how to run this project without making any changes . Juts press F5 key to run this project.
F5 command will launch the demo in command prompt with “Gulp Serve” command. You can also modify this command. If you want to change this command , Right click on your project & then go to “Properties”. In the Properties pane, go to Debug, Here you can modify command parameter for gulp.

Now lets run this project in local workbench first. Just hit F5. Gulp task will start & run the workbench.

Here is our web part. Now you just need to click on this web part to add in this page. It will look like :

It is very easy.
Url for local workbench : https://localhost:4321/temp/workbench.html
Url for SharePoint Online workbench : https://<<SiteUrl>>/_layouts/15/workbench.aspx