Showing posts with label Distributed Components Based Software Development. Show all posts
Showing posts with label Distributed Components Based Software Development. Show all posts

Friday, March 31, 2017

Generate SharePoint Online Rest API Authentications Details Using POSTMAN

Hi folks,
Today, SharePoint Online is the most preferred cloud based platform in many of the organizations to collaborate with external and internal parties, with organizing documents and access the information from any time anywhere.
SharePoint 2013 hosts a Representational State Transfer (REST) service. Using REST API, Developers can interact remotely with SharePoint data by using any technology that supports REST web requests.
In order to communicate SharePoint online REST services you needs to have following authentications keys.

1) BinarySecurityToken
2) rtFa & FedAuth Cookies
3) FormDigestValue 


In this post, I’ll demonstrate how to generate SharePoint Online Rest API authentications keys using Google chrome POSTMAN App.

Generate BinarySecurityToken

In order to get BinarySecurityToken, needs to use Microsoft Security Token Service put above mentioned address as the URL


Needs to add following XML Envelope as a message body, replace [username], [password] & [yourdomain] as per your environment.



When you go through the respond from STS Service, you should notice two main tags among respond envelope. Those are <wst:Lifetime> & <wst:RequestedSecurityToken>. Within RequestedSecurityToken tag we can identify the BinarySecurityToken, which we try to generate in this step, but make sure to follow the second step before the time period within <wst:Lifetime> token. Cause BinarySecurityToken is time based temporary key.   

Generate rtFa & FedAuth Cookies

Now, we need to POST generated BinarySecurityToken to SharePoint Online, if it is valid token SharePoint Online single sign on processes responding with two authentication cookies called rtFa & FedAuth.

In order to get the cookies, you need to enable POSTMAN interceptor. It’s allow to send requests which use browser’s cookies through POSTMAN.

https://[YourDomain].sharepoint.com/_forms/default.aspx?wa=wsignin1.0

Postman : Important sections are Highlighted


Generate FormDigestValue

Form digest value use as a credential validation key in SharePoint architecture. REST API call run inside the firewall, so REST calls are authenticated using the current user's credentials and they can get the form digest value.


Following values should declare as a headers in POSTMAN.
Cookie: rtFa=[rtFa]
Cookie: FedAuth=[ FedAuth]
Origin: [YourDomain].sharepoint.com




REST Call Demo

Using generated authentication values, we can simply test GET request. You need to replace following request as per your environment. Needs to add FormDigestValue as X-RequestDigest in header alone with above mentioned headers in Generate FormDigestValue step.

Additionally, I add optional header which format response as a JSON object.
Accept:application/json;odata=verbose



Happy Coding.
Regards,
Denuwan Himanga

Tuesday, September 1, 2015

LINQ (Language Integrated Query)



Hi guys,

The revolution of the computer programming technology rapidly change, Industry leaders such as Microsoft, Adobe try to add some values to their product in each releases. Within large amount of various product Microsoft own “C#” do an incredible revolution change in computer program developing history. They try to build universal language as well as universal IDE instead of different IDEs and different programing languages.   
According to their huge vision, Microsoft introduce Language Integrated Query with their amazing IDE called Visual Studio in 2008. Basically LINQ provide power full language capability to C#. Very simple explanation is, you can use only one programing language instead of SQL, XML etc.


In this demo, I’ll explain how to retrieve a data from SQL data base without using SQL query. LINQ consider table as a class, as well as data tuple as an object. That feature make computer programing technology to an amazing place J

Demo (Retrieving data from SQL database to WPF Application)    

Create a windows presentation foundation (WPF) application.



After that drag and drop a ‘list box’ from tool box, then formatted that list box according to our SQL table. In my case, Vehicle table formatted like this.


Using XAML code, we can easily format list box according to our requirement. Following XAML code segment format list box according to Vehicle table.

<ListBox x:Name="vehicleListBox" ItemsSource="{Binding}" Margin="0,40,0,0" >

            <ListBox.ItemTemplate>

                <DataTemplate>

                    <Grid>

                        <Grid.ColumnDefinitions>

                            <ColumnDefinition/>

                            <ColumnDefinition/>

                            <ColumnDefinition/>

                        </Grid.ColumnDefinitions>

                        <TextBlock Text="{Binding Vehicle_Name}" Grid.Column="0" Width="150"  FontSize="18" />

                        <TextBlock Text="{Binding Vehicle_Price}" Grid.Column="1" Width="150" FontSize="18"/>

                        <Image Source="{Binding Vehicle_Image}" Grid.Column="2" Width="150"/>

                    </Grid>

                </DataTemplate>

            </ListBox.ItemTemplate>

</ListBox>

Now we need to build a connection between SQL server and application, traditionally connection string responsibility for do this part. But in LINQ, add a .dbml Data classes and call when we need.
Add a .dbml data class to the project.


Add tables on to design surface.



After that, need to create a data classes data context object inside the application.

DataClasses1DataContext DB = new DataClasses1DataContext();

Finally we can easily call a values into special data type call ‘var’, this data type formatted according to values, which is assign to the variable. 

var result = from dt in DB.Vehicles
                         select dt;

vehicleListBox.ItemsSource = result.ToList<Vehicle>();
  
Source code/Project Repo.

Happy coding....

Best regards,
Denuwan Himanga.