/// <summary> /// Authorizes an Xbox Live token /// </summary> /// <param name="token">The Xbox Live Token</param> public static async Task <XboxLiveResponse <XboxLiveAuthorizeResponse> > AuthorizeXboxLiveAsync(string token) { // Call xbox live api to get tokens var httpClient = new HttpClient(); var response = await httpClient.PostAsync("https://xsts.auth.xboxlive.com/xsts/authorize", new StringContent(JsonConvert.SerializeObject(new XboxLiveRequest <XboxLiveAuthorize> { TokenType = "JWT", RelyingParty = "http://xboxlive.com", Properties = new XboxLiveAuthorize { SandboxId = "RETAIL", UserTokens = new[] { token } } }), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new FriendlyException("Invalid Xbox Live Token"); } var stringResponse = await response.Content.ReadAsStringAsync(); XboxLiveResponse <XboxLiveAuthorizeResponse> parsedResponse = null; try { parsedResponse = JsonConvert.DeserializeObject <XboxLiveResponse <XboxLiveAuthorizeResponse> >(stringResponse); } catch (Exception ex) { throw new FriendlyException("Invalid response from Xbox Live Authorization Server", ex); } if (parsedResponse.Token == null) { throw new FriendlyException("Invalid response from Xbox Live Authorization Server"); } return(parsedResponse); }
/// <summary> /// Authenticates a Windows Live Access Token with Xbox Live /// </summary> /// <param name="accessToken">The Windows Live Authentication Token</param> public static async Task <XboxLiveResponse <XboxLiveAuthenticateResponse> > AuthenticateXboxLiveAsync(string accessToken) { // Call xbox live api to get tokens var httpClient = new HttpClient(); var response = await httpClient.PostAsync("https://user.auth.xboxlive.com/user/authenticate", new StringContent(JsonConvert.SerializeObject(new XboxLiveRequest <XboxLiveAuthenticate> { TokenType = "JWT", RelyingParty = "http://auth.xboxlive.com", Properties = new XboxLiveAuthenticate { AuthMethod = "RPS", SiteName = "user.auth.xboxlive.com", RpsTicket = "t=" + accessToken } }), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new FriendlyException("Invalid Windows Live Access Token"); } var stringResponse = await response.Content.ReadAsStringAsync(); XboxLiveResponse <XboxLiveAuthenticateResponse> parsedResponse = null; try { parsedResponse = JsonConvert.DeserializeObject <XboxLiveResponse <XboxLiveAuthenticateResponse> >(stringResponse); } catch (Exception ex) { throw new FriendlyException("Invalid response from Xbox Live Authentication Server", ex); } if (parsedResponse.Token == null) { throw new FriendlyException("Invalid response from Xbox Live Authentication Server"); } return(parsedResponse); }