Friday, March 08, 2013

Authentication and Authorization with remote apps in Office 365 and SharePoint Online (Part 1)

This post is detailing about how you perform authentication and authorization from a remote app in SharePoint Online.
Especially, when the remote apps are running on a Non .Net technology platforms. Which means we can’t use the OOTB ‘TokenHelper’ class.
The entire flow needs to only use simple HttpRequests.

I am going to break this into 3 parts:

  1. Register a Remote App in SharePoint
  2. Get the 'AccessToken’ via the Azure ACS and SharePoint dance
  3. Call SharePoint REST Service with the AccessToken

Right now I am using the .Net HttpRequest class to perform this entire example and understand the entire flow. I am going to convert this into a JavaScript library soon so that it can be easily consumed by any external platforms. Ok, so lets get started.

Register a Remote App in SharePoint

There is some good guidance around registering an app for SharePoint but in our case we just want to register an app to perform the OAuth from a remote application so the only good option is to register it via ‘/_layouts/15/appregnew.aspx’.

image

There are 3 pieces of information that we need from the app registration:

  • client_id          = App Id
  • client_secret   = App Secret
  • redirect_uri     = Redirect URI

Get the 'AccessToken’ via the Azure ACS and SharePoint dance

There are 3 steps to this dance:

Step 1: Get the Request token

Getting the request token just requires a well formed Url with all the 3 pieces of information that we collected during the app registration.

image
(See this app permissions section for all the Scope and Rights available in SharePoint Online.)

This Url would redirect to the msonline login screen and after you enter the credentials if you prompt you with the trust screen:

image

image

Once you trust the app, it would redirect back to the ‘redirect_uri’ configured during the app registration along with the request token in the querystring

image

Step 2: Get the Realm

image
(This method is taken directly from TokenHelper class. The targetApplicationUri is the SharePoint Online url)

Step 3: And finally, Get the Access Token

Now that we have the requestToken and realm, we need to create a POST request to ACS to get back the access token

image

Call SharePoint REST Service with the AccessToken

The only thing to remember before calling the SharePoint REST API’s is to make sure that we requested the correct Scope and Rights while generating the access token. In the code above I request ‘AllProfile.Manage’ as my scope so I can call the User Profile REST API’s.

image

That’s it. Once we have the access token we can call all the SharePoint REST API’s that fetches the data. For creating, updating and deleting we need to get 1 more piece of data which is RequestDigest. I will cover this in my next post on uploading documents to SkyDrive Pro using REST API.

Reference Links: 

Tips and FAQs: OAuth and remote apps for SharePoint 2013
OAuth authentication and authorization flow for apps that ask for access permissions on the fly in SharePoint 2013 (advanced topic)
Get started with the SharePoint 2013 REST service
Using the SharePoint 2013 REST service

Download the Code from here

Friday, December 28, 2012

Authentication with Office 365 from an On-Premise Application

Recently I had a problem wherein I needed to connect to an Office 365 SharePoint site from an on Premise Windows App.
Now at first it seemed simple but as I drilled deeper I came across some challenges and while overcoming them I learned a lot more about how O365 Authentication works.

Before I go further I would like to point out 2 resources which helped me a lot in solving this challenge:

Here is that diagram which explains the AuthN basics for SharePoint Online in Office 365:

Passive claims AuthN 
(So the key here is to understand that SharePoint Online uses the binary token returned from the STS service located at login.microsoftonline.com to validate all requests.)

At first I tried using the “MsOnlineClaimsHelper” but I couldn’t get it to work as it kept on throwing errors while fetching the response using ‘WSTrustFeb2005ContractClient’. Then I looked at the WinRT code and it was doing the exact same thing but with much less dependencies. Just plain HttPWebRequests + XML.


But the WinRT code was specifically for REST API’s and not Client Object Model. So I modified the code a little bit to make it work with CSOM.

Here is my updated code:
image

.

.

 

Programmer Anarchy

I came across this refreshing ‘Post Agile Process’ video which revitalizes my earlier email on Test is Dead.

Here are some key takeaways for me out of this talk:

  • No need for testing infrastructure.
    (This is a culture shift and a revolutionary way to solve a lot of problems existing in the software world)

  • Break software into smaller more independent pieces.

  • Experimentation drives Innovation. (Move fast break things)

  • 2 key qualities for surviving in the ‘Modern Developer’ role:
    • Self-Leaner
    • Likes to Deliver (“Perfect” is the enemy of “Good Enough”)

  • At times, think of Software development as Manufacturing rather than Engineering.
    (Being a geek, it was a bit mind boggling for me to hear this first but I get the point)

What are your thoughts ?



Test is Dead !!!!

A refreshing way to present a very important point :  Test is Dead


Some moments from the video :

clip_image001
clip_image002
clip_image003
clip_image004

clip_image005

clip_image006
clip_image007

clip_image008

clip_image009

clip_image010

clip_image011

.

.

Thursday, October 25, 2012

SharePoint 2013 RTM Bits available on MSDN

 

Yesterday I download the SharePoint 2013 RTM bits from MSDN and created a brand new VM with all the updated bits.
While configuring SharePoint in the Standalone mode I had the below issue:

configissue - Copy

This is a known issue since 2010 and is related to the Search Service. I was able to resolve this by sharing the correct folder under
C:\Program Files\Microsoft Office Servers\14.0\Data\Office Server\Applications and assigning the required permissions as described here.

Monday, July 16, 2012

SharePoint 2013 and Office 2013 . . . .

 

Finally, Microsoft has announced the latest release of SharePoint 2013 (a.k.a SharePoint 15) along with Office 2013 (a.k.a Office 15).

There are some significant changes in the new App Model and would require a lot of unlearning and learning to get in pace. Personally, I like the overall direction in which MS is heading. I am a JavaScript fan and have been heavily using libraries like KnockoutJS and jQuery for a more end-to-end experience in SharePoint. So for me it feels like home Smile.
I have been working on this new App Model since over a month now and below are some tips for all the SharePoint Dev’s out there:

  • Embrace & Learn JavaScript  (As a real language)
  • SharePoint is not hammer and Lists are not nails
  • Separate the Concerns (Logic, Presentation, Persistence)
  • Understand the Mechanics of how things are working  (Fundamentally, SharePoint is just an Abstraction on top of an ASP.net Web Application)
  • Good Architecture is possible even with SharePoint involved Smile

I will be sharing my experiences on this new journey as I move along…

Enjoy !!

Friday, May 04, 2012

Choices for JavaScript frameworks..

 

I have been using jQuery since a long time now and looking for other frameworks which can help me take our SharePoint product to the next level.

Below are some of the interesting links that I came across :

I am leaning towards knokoutjs and also looking at datajs for manipulating OData feeds on O365..

Wednesday, April 18, 2012

Implementing federated identity in SharePoint 2010


Recently, I started working on a scenario wherein we had to move an existing online portal to SharePoint 2010. The first interesting challenge was authentication. How do we support existing users as well allow users to use other identity providers like live, facebook, google, myopenid  to access the portal. So I started researching on that and below are my findings:

For implementing federated identity in SharePoint 2010, we need to use Claims Authentication and below are our 3 options:

· Windows Claims
· Forms based Claims
· SAML Claims

Since we want multiple identity providers like google, yahoo, facebook, myopenid etc., my recommendation would be to use SAML claims via a custom Claims Provider. Below are some examples on how to do this:

For Live Id we can generate SAML tokens directly using MSM but for other providers in general we have 2 options :

1. Setup Azure’s Access Control Service (aka. ACS) with multiple Identity Providers (google, yahoo, facebook, live id, etc.) and add ACS as Trusted Provider in SharePoint
clip_image001
Pros/Cons :
ACS is more scalable and it has built-in support for Live Id, Google, Facebook, Yahoo and WS-Federation.
We have to pay the Azure Access Control Service cost

2. Create custom Claims Provider, integrate it with all the identity providers using OAuth Server Side flow and add the custom provider as Trusted Provider in SharePoint.I also found this custom claims provider component, which meets the requirements
clip_image002

Pros/Cons :
Custom claims provider would require some hefty code for generating SAML tokens and managing multiple identity providers.
Since this would be our custom component we do not have to pay for any other services.

Hope this helps.

Friday, March 02, 2012

Visual Studio 11 (Beta) and .Net 4.5 (RTM)

 

Visual Studio 11 (Beta) and .Net 4.5 (RTM) are now available for everyone : http://www.microsoft.com/visualstudio/11/en-us/downloads

Below are some of new enhancements that I like :

· New Metro UI
clip_image002

· Portal Class Libraries
clip_image004

· Searchable Solution Explorer
clip_image006

· Page Inspector
clip_image008
clip_image010

· CSS Editor
clip_image012

· Full Intellisense and enhanced editor support for JavaScript
clip_image014
clip_image016
clip_image018

Friday, January 20, 2012

Experiences with Binary and DNA abstractions

 

Since over a year now, I have been working on an Innovation product on SharePoint 2010 (read more…) and I would like to share some my experiences, architecting and developing it. Below I have tried to group my experiences into technical and non-technical headings and also shared some of the interesting resources that I went through.

In the next few posts I would try to expand some of these headings and talk about them in more details…

Thursday, October 20, 2011

First hands on Roslyn . . .

 

image

 

image

 

image

 

Microsoft “Roslyn” CTP

Traditionally, compilers are black boxes – source code goes in one end and object files or assemblies come out the other end. The Roslyn project changes that model by opening up the Visual Basic and C# compilers as APIs. These APIs allow tools and end-users to share in the wealth of information the compilers have about code. The Roslyn CTP previews the next generation of language object models for code generation, analysis, and refactoring, and the upcoming support for scripting and interactive use of VB and C#.

http://msdn.microsoft.com/en-us/roslyn

AddIn