Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function doPTCLogin() {
- if (!checkParams()){
- return;
- }
- toggleLogin(true);
- jQuery('#ptc_errors').html('');
- var username = jQuery('#ptc_username').val(),
- password = jQuery('#ptc_password').val();
- // Reset cookie jar
- ptcJar = request.jar();
- // Get Login session from SSO servers
- ptcReq.get('https://sso.pokemon.com/sso/login?service=https%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize',
- function(error, response, body) {
- if (!error && response.statusCode == 200) {
- doPTCLoginStep2(username, password, JSON.parse(body));
- } else {
- console.log(error);
- toggleLogin(false);
- alert('Oops! Something went wrong and we couldn\'t ' +
- 'log you in. Please try again. Code 6.');
- }
- });
- return false;
- }
- function doPTCLoginStep2(user, pass, session) {
- var loginData = {
- 'lt': session.lt,
- 'execution': session.execution,
- '_eventId': 'submit',
- 'username': user,
- 'password': pass
- };
- ptcReq.post(
- 'https://sso.pokemon.com/sso/login?service=https%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize',
- {form: loginData},
- function (error, response, body) {
- if (!error && response.statusCode == 302) {
- var rawRedirect = response.headers.location;
- handlePokemonCallback(rawRedirect);
- } else {
- toggleLogin(false);
- var errors = null;
- try {
- errors = JSON.parse(body).errors;
- errors = errors.join(' ');
- } catch(e) {}
- if (errors) {
- jQuery('#ptc_errors').html(errors);
- } else {
- alert('Oops! Something went wrong and we couldn\'t ' +
- 'log you in. Please try again. Code 7.');
- }
- }
- }
- );
- }
- function handlePokemonCallback(newUrl) {
- var parsedUrl = url.parse(newUrl, true);
- if (parsedUrl.hostname != 'sso.pokemon.com') {
- toggleLogin(false);
- alert('Oops! Something went wrong and we couldn\'t ' +
- 'log you in. Please try again. Code 8.');
- return;
- }
- var raw_code = parsedUrl.query.ticket;
- var code = (raw_code && raw_code.length > 1) ? raw_code : null;
- // If there is a code, proceed to get token from oauth
- if (code) {
- request.post(
- 'https://sso.pokemon.com/sso/oauth2.0/accessToken',
- { form: {
- 'client_id': 'mobile-app_pokemon-go',
- 'redirect_uri': 'https://www.nianticlabs.com/pokemongo/error',
- 'client_secret': 'w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR',
- 'grant_type': 'refresh_token',
- 'code': code,
- } },
- function (error, response, body) {
- if (!error && response.statusCode == 200) {
- console.log(querystring.parse(body));
- completeLogin('ptc', querystring.parse(body).access_token);
- } else {
- toggleLogin(false);
- alert('Oops! Something went wrong and we couldn\'t ' +
- 'log you in. Please try again. Code 3.');
- }
- }
- );
- } else {
- toggleLogin(false);
- alert('Oops! Something went wrong and we couldn\'t ' +
- 'log you in. Please try again. Code 2.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement