Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing refresh token #22

Merged
merged 3 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions PokemonGo.RocketAPI/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using PokemonGo.RocketAPI.Login;
using static PokemonGo.RocketAPI.GeneratedCode.Response.Types;
using System.IO;
using System.Configuration;

namespace PokemonGo.RocketAPI
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public Client(ISettings settings)
};
_httpClient = new HttpClient(new RetryHandler(handler));
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Niantic App");
//"Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G900F Build/LMY48G)");
//"Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G900F Build/LMY48G)");
_httpClient.DefaultRequestHeaders.ExpectContinue = false;
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Connection", "keep-alive");
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "*/*");
Expand Down Expand Up @@ -82,15 +83,15 @@ public async Task DoGoogleLogin()
tokenResponse = await GoogleLogin.GetAccessToken(Settings.GoogleRefreshToken);
AccessToken = tokenResponse?.id_token;
}

if (AccessToken == null)
{
var deviceCode = await GoogleLogin.GetDeviceCode();
tokenResponse = await GoogleLogin.GetAccessToken(deviceCode);
Settings.GoogleRefreshToken = tokenResponse?.refresh_token;
AccessToken = tokenResponse?.id_token;
}

}

/// <summary>
Expand Down Expand Up @@ -135,7 +136,7 @@ public async Task SetServer()
RequestType.GET_PLAYER, RequestType.GET_HATCHED_OBJECTS, RequestType.GET_INVENTORY,
RequestType.CHECK_AWARDED_BADGES, RequestType.DOWNLOAD_SETTINGS);
var serverResponse = await _httpClient.PostProto<Request>(Resources.RpcUrl, serverRequest);

if (serverResponse.Auth == null)
throw new AccessTokenExpiredException();

Expand Down
2 changes: 2 additions & 0 deletions PokemonGo.RocketAPI/Login/GoogleLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static async Task<TokenResponseModel> GetAccessToken(DeviceCodeModel devi
tokenResponse = await PollSubmittedToken(deviceCode.device_code);
} while (tokenResponse.access_token == null || tokenResponse.refresh_token == null);

Logger.Write($"Save the refresh token in your settings: {tokenResponse.refresh_token}", LogLevel.None);

return tokenResponse;
}

Expand Down