Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Live Connect Rest API: Signing user in?

I am working on a poc using the Live Connect Rest API.

(Documentation here: http://msdn.microsoft.com/en-us/windowslive/default)

Using the example from the link below I am able to login a user and requesting consent for certain actions.

However, I have several questions related to this:

  • How can I skip requesting consent when the user has already granted consent before?
  • What is a save way to store the 'access_token' between application runs?
  • How can I make use of single sign on using the Rest API?

Signing in: http://msdn.microsoft.com/en-us/windowslive/hh278363#rest

Thanks!

like image 495
SaphuA Avatar asked Nov 13 '22 13:11

SaphuA


1 Answers

  • If the user previously granted the consent you need, Live will not prompt the user to grant again. You don't need to skip manually.
  • I don't know what your platform is, but you may find someway to make your app's storage isolated or encrypted. What is important is that the token have an expire time. You may also consider using a controller that Microsoft provides, which can handle all the things related to Live login. Here is my WP8 example:

Add this in the XAML file:

 <Controls:SignInButton Grid.Row="0" ClientId="yourid" Scopes="wl.offline_access wl.skydrive_update" HorizontalAlignment="Right" VerticalAlignment="Bottom" SessionChanged="OnSessionChanged" 
                                Margin="0,0,0,0" Width="160" Height="70" Background="Transparent" BorderBrush="{StaticResource TransparentBrush}" />

Before that, add this line to the same file:

xmlns:Controls="clr-namespace:Microsoft.Live.Controls;assembly=Microsoft.Live.Controls"

And the control will look like this: enter image description here

It will automatically update as user login or sign out.

In your C# code, add the OnSessionChanged event handler to it:

 private void OnSessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
    {
        //sign in
        if (e.Error != null)
        {
            MessageBox.Show(e.Error.Message);
            return;
        }

        if (e.Status == LiveConnectSessionStatus.Connected)
        {
            ((App) Application.Current).Session = e.Session;
            connectClient = new LiveConnectClient(((App) Application.Current).Session);
                       }
        }
    }
  • This article maybe helpful here here
like image 82
Shone Avatar answered Nov 16 '22 04:11

Shone