Skip to main content

Microsoft Live - Live Connect

Windows LIVE series:

Si am ajuns la lucruri mai interesante. O sa incep azi sa povestim despre Live Connect. Ce putem sa facem cu Live Connect? Un user conectat la aplicatia noastra se poate conecta la email, SkyDrive, messeaging sau orice alt serviciu folosind un Live ID.
Cum il folosim? Partea buna in toata nebunia asta este ca API-ul de Live Connect este conform standardului OAuth 2.0 si suporta atat JSON cat si protocolul XMPP. Acesta poate sa fie integrat in orice fel de aplicatie, indiferent de limbaj sau platforma.
Daca e prima data cand auziti de XMPP, trebuie sa stiti ca acesta este un standard de comunicare pentru aplicatiile de chat, care permite ca sa ne integram aplicatiile proprii de chat cu Messenger-ul de la Microsoft faca nici o problema.
In urmatorul exemplu o sa vedem ce trebuie sa facem ca un utilizator sa se autentifice prin apeluri de tip REST:
- redirectam userul spre urmatoarea pagina, unde reprezinta id-ul pe care l-am primit cand ne-am inregistrat aplicatia, iar reprezinta url spre care userul o sa fie redirectionat in momentul in care procesul de autentificare s-a terminat cu succes. Despre parametrul vrea sa vorbim putin mai tarziu
https://oauth.live.com/authorize?client_id=<client_id>&scope=<scope>&response_type=code&redirect_uri=<redirect_url>
- dupa ce autentificare sa terminat, userul este redirectionat spre . In url o sa avem un parametru cu numele de 'code', pe baza caruia, putem sa obtinem token-ul de acces a userului. Folosind acest cod putem sa accesam orice serviciu integrat cu Live Connect. Mai jos gasiti modul in care serverul o sa ne apeleze aplicatia:
<redirect_url>?code=<o_cheie_unica>
- token-ul de acces a userului, de care avem nevoie ca sa accesam serviciile dorite se obtine apeland urmatorul url:
https://oauth.live.com/token?client_id=<client_id>&redirect_uri=<redirect_url>&client_secret=<client_secret_key>&code=<code>&grant_type=authorization_code

  • client_secret_key - reprezinta cheia unica pe care am obtinut-o cand am inregistrat aplicatia
  • authorization_code - specifica modul prin care vrem sa obtinem token-ul clientului. In cazul nostru pe baza codului pe care l-am obtinut la pasul precedent
Raspunsul care o sa ne vina in urma ultimului apel o sa contina 5 elemente:
  1. access_token - token-ul de acces la servicii, pe care o sa il folosim cand vrem sa accesam un serviciu
  2. authentification_token - token-ul de autentificare
  3. scope - pentru ce servicii poate sa fie folosit token-ul
  4. token_type - tipul de token obtinut( de obicei o sa fie 'bearer')
  5. expires_in - durata de timp cand token-ul de acces poate sa fie folosit( valoarea este exprimata in secunde).
Mai jos gasiti un exemplu de raspuns in format JSON, pe care il primim in urma apelului:
{    "access_token" : "ExxXCSFCCWEECECE...AA==",    "authentication_token" : "423423-423424-2342342";    "expires_in" : 3600,    "scope" : "wl.signin wl.basic wl.calendars",    "token_type" : "bearer"}
Intr-un alt post o sa revin cu o descriere despre cum consumam serviciile integrate cu Live ID. Ce trebuie sa tinem minte este ca ce trebuie sa facem este sa apelam un url, cu anumiti parametrii in care sa includem si token-ul de acces.
Am ramas dator cu o explicatie. Ce este un SCOPE? Actiune prin care cerem permisiune unui user sa accesam unu sau mai multe servicii in numele acestuia.
Exista trei tipuri de scope:
  • core - sunt serviciile de baza precum: conectare la Live Connect, lista de contacte, acces offline la date, fara ca userul sa mai fie nevoit sa se autentifice in aplicatia noastra
  • extended - cateva servicii auxiliare, care completeaza functionalitatiile de baza( calendar, poze, skydrive, messeger, etc)
  • developer - servici create de catre alti dezvoltatori, care sunt integrate cu Live Connect( orice persoana poate sa scrie o aplicatie si sa fie accesibila de catre orice persoana prin intermediul Live Connect)
Pentru o lista detaliata puteti accesa urmatorul link http://msdn.microsoft.com/en-us/library/hh243646.aspx.

Comments

Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…