//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.ApplicationBlock {
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
public class WindowsLiveClient : WebServerClient {
private static readonly AuthorizationServerDescription WindowsLiveDescription = new AuthorizationServerDescription {
TokenEndpoint = new Uri("https://oauth.live.com/token"),
AuthorizationEndpoint = new Uri("https://oauth.live.com/authorize"),
ProtocolVersion = ProtocolVersion.V20
};
///
/// Initializes a new instance of the class.
///
public WindowsLiveClient()
: base(WindowsLiveDescription) {
}
public async Task GetGraphAsync(IAuthorizationState authState, string[] fields = null, CancellationToken cancellationToken = default(CancellationToken)) {
if ((authState != null) && (authState.AccessToken != null)) {
var httpClient = new HttpClient(this.CreateAuthorizingHandler(authState));
using (var response = await httpClient.GetAsync("https://apis.live.net/v5.0/me", cancellationToken)) {
response.EnsureSuccessStatusCode();
using (var responseStream = await response.Content.ReadAsStreamAsync()) {
// string debugJsonStr = new StreamReader(responseStream).ReadToEnd();
WindowsLiveGraph windowsLiveGraph = WindowsLiveGraph.Deserialize(responseStream);
// picture type resolution test 1
// &type=small 96x96
// &type=medium 96x96
// &type=large 448x448
windowsLiveGraph.AvatarUrl =
new Uri("https://apis.live.net/v5.0/me/picture?access_token=" + Uri.EscapeDataString(authState.AccessToken));
return windowsLiveGraph;
}
}
}
return null;
}
///
/// Well-known scopes defined by the Windows Live service.
///
///
/// This sample includes just a few scopes. For a complete list of scopes please refer to:
/// http://msdn.microsoft.com/en-us/library/hh243646.aspx
///
public static class Scopes {
#region Core Scopes
///
/// The ability of an app to read and update a user's info at any time. Without this scope, an app can access the user's info only while the user is signed in to Live Connect and is using your app.
///
public const string OfflineAccess = "wl.offline_access";
///
/// Single sign-in behavior. With single sign-in, users who are already signed in to Live Connect are also signed in to your website.
///
public const string SignIn = "wl.signin";
///
/// Read access to a user's basic profile info. Also enables read access to a user's list of contacts.
///
public const string Basic = "wl.basic";
#endregion
#region Extended Scopes
///
/// Read access to a user's birthday info including birth day, month, and year.
///
public const string Birthday = "wl.birthday";
///
/// Read access to a user's calendars and events.
///
public const string Calendars = "wl.calendars";
///
/// Read and write access to a user's calendars and events.
///
public const string CalendarsUpdate = "wl.calendars_update";
///
/// Read access to the birth day and birth month of a user's contacts. Note that this also gives read access to the user's birth day, birth month, and birth year.
///
public const string ContactsBirthday = "wl.contacts_birthday";
///
/// Creation of new contacts in the user's address book.
///
public const string ContactsCreate = "wl.contacts_create";
///
/// Read access to a user's calendars and events. Also enables read access to any calendars and events that other users have shared with the user.
///
public const string ContactsCalendars = "wl.contacts_calendars";
///
/// Read access to a user's albums, photos, videos, and audio, and their associated comments and tags. Also enables read access to any albums, photos, videos, and audio that other users have shared with the user.
///
public const string ContactsPhotos = "wl.contacts_photos";
///
/// Read access to Microsoft SkyDrive files that other users have shared with the user. Note that this also gives read access to the user's files stored in SkyDrive.
///
public const string ContactsSkydrive = "wl.contacts_skydrive";
///
/// Read access to a user's personal, preferred, and business email addresses.
///
public const string Emails = "wl.emails";
///
/// Creation of events on the user's default calendar.
///
public const string EventsCreate = "wl.events_create";
///
/// Enables signing in to the Windows Live Messenger Extensible Messaging and Presence Protocol (XMPP) service.
///
public const string Messenger = "wl.messenger";
///
/// Read access to a user's personal, business, and mobile phone numbers.
///
public const string PhoneNumbers = "wl.phone_numbers";
///
/// Read access to a user's photos, videos, audio, and albums.
///
public const string Photos = "wl.photos";
///
/// Read access to a user's postal addresses.
///
public const string PostalAddresses = "wl.postal_addresses";
///
/// Enables updating a user's status message.
///
public const string Share = "wl.share";
///
/// Read access to a user's files stored in SkyDrive.
///
public const string Skydrive = "wl.skydrive";
///
/// Read and write access to a user's files stored in SkyDrive.
///
public const string SkydriveUpdate = "wl.skydrive_update";
///
/// Read access to a user's employer and work position information.
///
public const string WorkProfile = "wl.work_profile";
#endregion
}
}
}