Guest User

Untitled

a guest
Jul 19th, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.55 KB | None | 0 0
  1. function PobierzTokenTwitch(login, haslo: string): string;
  2. var
  3.   IdHTTP: TIdHTTP;
  4.   IdSSL: TIdSSLIOHandlerSocketOpenSSL;
  5.   HTML, authToken: string;
  6.   parametry: TStringList;
  7.   poczatek, koniec: integer;
  8.   strumien: TMemoryStream;
  9.   // stringDoWyslania: TStringStream;
  10. begin
  11.   try
  12.     IdHTTP := TIdHTTP.Create;
  13.     parametry := TStringList.Create;
  14.     strumien := TMemoryStream.Create;
  15.     try
  16.       IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
  17.       IdHTTP.IOHandler := IdSSL;
  18.       IdHTTP.AllowCookies := True;
  19.       IdHTTP.CookieManager := Form1.IdCookieManager1;
  20.       Form1.IdCookieManager1.CookieCollection.Clear;
  21.       IdHTTP.HandleRedirects := True;
  22.       HTML := IdHTTP.Get('http://www.twitch.tv/login');
  23.       poczatek := Pos('"authenticity_token" type="hidden" value="', HTML) + Length('"authenticity_token" type="hidden" value="');
  24.       koniec := PosEx('"', HTML, poczatek);
  25.       authToken := copy(HTML, poczatek, koniec - poczatek);
  26.  
  27.       try
  28.         parametry.Add('utf8=✓');
  29.         parametry.Add('authenticity_token=' + authToken);
  30.         parametry.Add('redirect_on_login=');
  31.         parametry.Add('embed_form=false');
  32.         parametry.Add('login=' + login);
  33.         parametry.Add('password=' + haslo);
  34.         // try
  35.  
  36.         IdHTTP.Post('https://secure.twitch.tv/user/login', parametry, strumien, IndyTextEncoding_UTF8());
  37.         // except
  38.         // end;
  39.         Delay(1000);
  40.         parametry.Clear;
  41.         parametry.Add('utf8=✓');
  42.         parametry.Add('authenticity_token=' + authToken);
  43.         parametry.Add('login_type=login');
  44.         parametry.Add('response_type=token');
  45.         parametry.Add('client_id=smb61nyd0vxmqdn9d3k735qbx41cdyg');
  46.         parametry.Add('redirect_uri=http://localhost');
  47.         parametry.Add('scope=chat_login channel_editor channel_read');
  48.         IdHTTP.Post('https://api.twitch.tv/kraken/oauth2/allow', parametry, strumien, IndyTextEncoding_UTF8());
  49.         IdHTTP.Get('https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=smb61nyd0vxmqdn9d3k735qbx41cdyg' +
  50.           '&redirect_uri=http://localhost&scope=chat_login+channel_editor+channel_read');
  51.       finally
  52.         poczatek := Pos('#access_token', IdHTTP.Response.Location);
  53.         if poczatek > 0 then Result := 'oauth:' + copy(IdHTTP.Response.Location, poczatek + 14, 31);
  54.       end;
  55.     finally
  56.       IdHTTP.Free;
  57.       parametry.Free;
  58.  
  59.       strumien.Free;
  60.       // IdSSLOpenSSL.UnLoadOpenSSLLibrary();
  61.     end;
  62.   except
  63.     // on E: Exception do
  64.     // ShowMessage(E.Message);
  65.   end;
  66. end;
Advertisement
Add Comment
Please, Sign In to add comment