private async Task <AuthResponse <XuiDisplayClaims <Xui> > > DoUserAuth(string accessToken) { var key = EcDsa.ExportParameters(false); var authRequest = new AuthRequest { RelyingParty = "http://auth.xboxlive.com", TokenType = "JWT", Properties = new Dictionary <string, object>() { { "AuthMethod", "RPS" }, { "RpsTicket", "t=" + accessToken }, { "SiteName", "user.auth.xboxlive.com" }, { "ProofKey", new Dictionary <string, string>() { { "crv", "P-256" }, { "alg", "ES256" }, { "use", "sig" }, { "kty", "EC" }, { "x", UrlSafe(key.Q.X) }, { "y", UrlSafe(key.Q.Y) } } } } }; AuthResponse <XuiDisplayClaims <Xui> > authResponse; //using (var client = new HttpClient()) var client = GetClient(); { using (var r = new HttpRequestMessage(HttpMethod.Post, UserAuth)) { r.Headers.Add("x-xbl-contract-version", "1"); r.Content = SetHttpContent(authRequest, out var jsonData); Sign(r, jsonData); using (var response = await client .SendAsync(r, HttpCompletionOption.ResponseContentRead) .ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); authResponse = JsonConvert.DeserializeObject <AuthResponse <XuiDisplayClaims <Xui> > >( await response.Content.ReadAsStringAsync()); Log.Debug($"User Auth Result: {JsonConvert.SerializeObject(authResponse)}"); } } } return(authResponse); }
private async Task <AuthResponse <XuiDisplayClaims <XstsXui> > > DoXsts(AuthResponse <DeviceDisplayClaims> deviceToken, AuthResponse <TitleDisplayClaims> titleToken, string userToken) { var key = EcDsa.ExportParameters(false); var authRequest = new AuthRequest { RelyingParty = "https://multiplayer.minecraft.net/", TokenType = "JWT", Properties = new Dictionary <string, object>() { { "UserTokens", new string[] { userToken } }, { "SandboxId", "RETAIL" }, { "ProofKey", new Dictionary <string, string>() { { "crv", "P-256" }, { "alg", "ES256" }, { "use", "sig" }, { "kty", "EC" }, { "x", UrlSafe(key.Q.X) }, { "y", UrlSafe(key.Q.Y) } } } } }; AuthResponse <XuiDisplayClaims <XstsXui> > titleAuthResponse; var client = GetClient(); //using (var client = new HttpClient()) { using (var r = new HttpRequestMessage(HttpMethod.Post, XblAuth)) { r.Headers.Add("x-xbl-contract-version", "1"); r.Content = SetHttpContent(authRequest, out var jsonData); Sign(r, jsonData); using (var response = await client .SendAsync(r, HttpCompletionOption.ResponseContentRead) .ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); var rawResponse = await response.Content.ReadAsStringAsync(); titleAuthResponse = JsonConvert.DeserializeObject <AuthResponse <XuiDisplayClaims <XstsXui> > >( rawResponse); Log.Debug($"Xsts Auth: {rawResponse}"); } } } return(titleAuthResponse); }
private async Task <AuthResponse <DeviceDisplayClaims> > DoDeviceAuth(string token) { var id = Guid.NewGuid().ToString(); var serial = Guid.NewGuid().ToString(); var key = EcDsa.ExportParameters(false); var authRequest = new AuthRequest { RelyingParty = "http://auth.xboxlive.com", TokenType = "JWT", Properties = new Dictionary <string, object>() { // {"RpsTicket", token}, // {"SiteName", "user.auth.xboxlive.com"}, { "DeviceType", "Nintendo" }, { "Id", id }, { "SerialNumber", serial }, { "Version", "0.0.0.0" }, { "AuthMethod", "ProofOfPossession" }, { "ProofKey", new Dictionary <string, string>() { { "crv", "P-256" }, { "alg", "ES256" }, { "use", "sig" }, { "kty", "EC" }, { "x", UrlSafe(key.Q.X) }, { "y", UrlSafe(key.Q.Y) } } } } }; AuthResponse <DeviceDisplayClaims> deviceAuthResponse; //using (var client = new HttpClient()) var client = GetClient(); using (var r = new HttpRequestMessage(HttpMethod.Post, DeviceAuth)) { r.Headers.Add("x-xbl-contract-version", "1"); //var json = JsonConvert.SerializeObject(authRequest); //Console.WriteLine($"Device Request: " + json); r.Content = SetHttpContent(authRequest, out var jsonData); Sign(r, jsonData); Console.WriteLine(); Console.WriteLine($"Request data: {r.Content.ReadAsStringAsync().Result}"); using (var response = await client .SendAsync(r, HttpCompletionOption.ResponseContentRead) .ConfigureAwait(false)) { var resp = await response.Content.ReadAsStringAsync(); Console.WriteLine($"DEV AUTH: {resp}"); response.EnsureSuccessStatusCode(); deviceAuthResponse = JsonConvert.DeserializeObject <AuthResponse <DeviceDisplayClaims> >( resp); Console.WriteLine($"Device Auth: {JsonConvert.SerializeObject(deviceAuthResponse)}"); Console.WriteLine(); } } return(deviceAuthResponse); }