Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PobierzTokenTwitch(login, haslo: string): string;
- var
- IdHTTP: TIdHTTP;
- IdSSL: TIdSSLIOHandlerSocketOpenSSL;
- HTML, authToken: string;
- parametry: TStringList;
- poczatek, koniec: integer;
- strumien: TMemoryStream;
- fLogin, fHaslo: string;
- begin
- fLogin := login;
- fHaslo := haslo;
- try
- IdHTTP := TIdHTTP.Create;
- try
- IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
- IdHTTP.IOHandler := IdSSL;
- IdHTTP.AllowCookies := True;
- IdHTTP.CookieManager := Form1.IdCookieManager1;
- IdHTTP.HandleRedirects := True;
- // Logowanie do Twitcha
- HTML := IdHTTP.Get('http://www.twitch.tv/login');
- poczatek := Pos('"authenticity_token" type="hidden" value="', HTML) +
- Length('"authenticity_token" type="hidden" value="');
- koniec := PosEx('"', HTML, poczatek);
- authToken := copy(HTML, poczatek, koniec - poczatek);
- // ShowMessage(authToken);
- parametry := TStringList.Create;
- try
- parametry.Add('utf8=✓');
- parametry.Add('authenticity_token=' + authToken);
- parametry.Add('redirect_on_login=');
- parametry.Add('embed_form=false');
- parametry.Add('user[login]=' + login);
- parametry.Add('user[password]=' + haslo);
- try
- strumien := TMemoryStream.Create;
- IdHTTP.Post('https://secure.twitch.tv/user/login', parametry,
- strumien, IndyUTF8Encoding);
- except
- end;
- // Autoryzacja dla launchera
- parametry.Clear;
- parametry.Add('utf8=✓');
- parametry.Add('authenticity_token=' + authToken);
- parametry.Add('login_type=login');
- parametry.Add('response_type=token');
- parametry.Add('client_id=xxx');
- parametry.Add('redirect_uri=http://localhost');
- parametry.Add('scope=chat_login');
- try
- IdHTTP.Post('https://api.twitch.tv/kraken/oauth2/allow', parametry,
- strumien, IndyUTF8Encoding);
- IdHTTP.Get
- ('https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=xxx'
- + '&redirect_uri=http://localhost&scope=chat_login');
- except
- end;
- finally
- // Wyodrębnienie tokena
- poczatek := Pos('#access_token', IdHTTP.Response.Location);
- if poczatek > 0 then
- Result := 'oauth:' + copy(IdHTTP.Response.Location,
- poczatek + 14, 31);
- parametry.Free;
- IdSSL.Free;
- strumien.Free;
- end;
- finally
- idHTTP.Free;
- end;
- except
- on E: Exception do
- ShowMessage(E.Message);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement