Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit 4366071

Browse files
author
Robert McLaws (Microsoft MVP)
authored
Merge pull request #1794 from robertmclaws/master
Temporary fix for cookie problems
2 parents 5bc83d9 + f06a826 commit 4366071

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

PokemonGo-UWP/project.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"dependencies": {
3-
"HockeySDK.UWP": "4.1.4",
3+
"HockeySDK.UWP": "4.1.5",
44
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
55
"Newtonsoft.Json": "9.0.1",
66
"NotificationsExtensions.Win10": "14332.0.2",
77
"Octokit": "0.22.0",
8-
"Template10": "1.1.12-preview-160712",
8+
"Template10": "1.1.12",
99
"UniversalMapControl": "0.3.45",
1010
"WinRTXamlToolkit.Controls.Gauge.UWP": "2.0.0",
1111
"Xam.Plugin.DeviceMotion": "1.1.2",
12-
"XamlAnimatedGif": "1.1.5"
12+
"XamlAnimatedGif": "1.1.6"
1313
},
1414
"frameworks": {
1515
"uap10.0": {}

PokemonGoAPI/Extensions/CookieContainerExtensions.cs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Collections.Generic;
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Dynamic;
24
using System.Reflection;
35

46
namespace System.Net
@@ -19,21 +21,31 @@ public static class CookieContainerExtensions
1921
/// <returns></returns>
2022
public static IEnumerable<Cookie> GetCookies(this CookieContainer cookieContainer, string domain)
2123
{
24+
#if WINDOWS_UWP
2225
var domainTable = GetFieldValue<dynamic>(cookieContainer, "_domainTable");
23-
foreach (var entry in domainTable)
26+
#else
27+
var domainTable = GetFieldValue<dynamic>(cookieContainer, "m_domainTable");
28+
#endif
29+
if (domainTable as IEnumerable != null)
2430
{
25-
string key = GetPropertyValue<string>(entry, "Key");
26-
27-
if (key.Contains(domain))
31+
foreach (var entry in domainTable)
2832
{
29-
var value = GetPropertyValue<dynamic>(entry, "Value");
33+
string key = GetPropertyValue<string>(entry, "Key");
3034

31-
var internalList = GetFieldValue<SortedList<string, CookieCollection>>(value, "_list");
32-
foreach (var li in internalList)
35+
if (key.Contains(domain))
3336
{
34-
foreach (Cookie cookie in li.Value)
37+
var value = GetPropertyValue<dynamic>(entry, "Value");
38+
#if WINDOWS_UWP
39+
var internalList = GetFieldValue<SortedList<string, CookieCollection>>(value, "_list");
40+
#else
41+
var internalList = GetFieldValue<SortedList<string, CookieCollection>>(value, "m_list");
42+
#endif
43+
foreach (var li in internalList)
3544
{
36-
yield return cookie;
45+
foreach (Cookie cookie in li.Value)
46+
{
47+
yield return cookie;
48+
}
3749
}
3850
}
3951
}
@@ -49,9 +61,16 @@ public static IEnumerable<Cookie> GetCookies(this CookieContainer cookieContaine
4961
/// <returns></returns>
5062
internal static T GetFieldValue<T>(object instance, string fieldName)
5163
{
52-
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
53-
FieldInfo fi = instance.GetType().GetField(fieldName, bindFlags);
54-
return (T)fi.GetValue(instance);
64+
try
65+
{
66+
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
67+
FieldInfo fi = instance.GetType().GetField(fieldName, bindFlags);
68+
return fi != null ? (T)fi.GetValue(instance) : (T)new object();
69+
}
70+
catch (Exception ex)
71+
{
72+
return (T)new object();
73+
}
5574
}
5675

5776
/// <summary>

PokemonGoAPI/Login/PtcLogin.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ public async Task<AccessToken> GetAccessToken()
7979
{
8080
AccessToken accessToken;
8181
PtcLoginParameters loginData = null;
82-
var cookies = Cookies.GetCookies("sso.pokemon.com").ToList();
82+
Cookies = new CookieContainer();
83+
//var cookies = Cookies.GetCookies("sso.pokemon.com")?.ToList();
8384
// @robertmclaws: "CASTGC" is the name of the login cookie that the service looks for, afaik.
8485
// The second one is listed as a backup in case they change the cookie name.
85-
if (!cookies.Any(c => c.Name == "CASTGC") || cookies.Count == 0)
86-
{
86+
//if (!cookies.Any(c => c.Name == "CASTGC") || cookies.Count == 0)
87+
//{
8788
loginData = await GetLoginParameters().ConfigureAwait(false);
88-
}
89+
//}
8990
var authTicket = await GetAuthenticationTicket(loginData).ConfigureAwait(false);
9091
accessToken = await GetOAuthToken(authTicket).ConfigureAwait(false);
9192

@@ -99,7 +100,6 @@ public async Task<AccessToken> GetAccessToken()
99100
/// <summary>
100101
/// Responsible for retrieving login parameters for <see cref="GetAuthenticationTicket" />.
101102
/// </summary>
102-
/// <param name="httpClient">An initialized <see cref="HttpClient" /></param>
103103
/// <returns><see cref="PtcLoginParameters" /> for <see cref="GetAuthenticationTicket" />.</returns>
104104
private async Task<PtcLoginParameters> GetLoginParameters()
105105
{
@@ -112,7 +112,6 @@ private async Task<PtcLoginParameters> GetLoginParameters()
112112
/// <summary>
113113
/// Authenticates against the PTC login service and acquires an Authentication Ticket.
114114
/// </summary>
115-
/// <param name="httpClient">The <see cref="HttpClient"/> instance to use for this request.</param>
116115
/// <param name="loginData">The <see cref="PtcLoginParameters" /> to use from this request. Obtained by calling <see cref="GetLoginParameters(HttpClient)"/>.</param>
117116
/// <returns></returns>
118117
private async Task<string> GetAuthenticationTicket(PtcLoginParameters loginData)

0 commit comments

Comments
 (0)