delthas / JavaSkype

A lightweight, comprehensive Java API for Skype using MSNP24
MIT License
72 stars 28 forks source link

Add support for Microsoft accounts #24

Open delthas opened 7 years ago

delthas commented 7 years ago

Some users would like to use this library with Microsoft accounts (#23), maybe add that in the future.

MrPowerGamerBR commented 7 years ago

There was a code on how to login in a Microsoft account at https://github.com/samczsun/Skype4J/issues/128 , but the message was deleted (and the user account doesn't exist anymore)

Maybe @Manevolent still has his fix for Skype4J?

delthas commented 7 years ago

I think I know how to do this, the process is detailed here: https://github.com/msndevs/protocol-docs/wiki/Authentication#microsoft-accounts

Manevolent commented 7 years ago

I do!

https://gist.github.com/Manevolent/1c6bc379c10c1e50358e8f2e2356fef7

That's what I've been using since the mentioned ticket, I made some minor changes to the original poster's source but this has been working fine for me.

JSONObject object = LiveLoginHelper.getXTokenObject(username, password);
String skypeToken = object.getString("skypetoken");
String skypeId = object.getString("skypeid");

MSFTSkypeClient client = new MSFTSkypeClient.Builder(skypeToken, skypeId)
            .withLogger(Logger.getGlobal())
            .withExceptionHandler(handler)
            .withAllResources().build();

client.login();
...

The changes I made just sanitize the XML email/password, and acknowledge the "skypeId" returned in my code block above, which is very important if you're using a migrated (skypename -> email) account, which I have been using. I've been having some issues with the auth sticking, though, and sometimes my bot will randomly log out and stay that way until I address it. Until I figure that out, I'll probably wait to make a pull request.

Also, maven deps:

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.5</version>
        </dependency>

Also, JSoup is used, too.

klingan commented 7 years ago

@Manevolent since we are 4 months later, were you able to resolve your auth issues? A pull request would still come in handy :hankey:

simk0024 commented 7 years ago

I think this should be put in higher priority, as all skype account are forced to link with Microsoft now...

ruha9005 commented 7 years ago

May be it can help: https://skpy.t.allofti.me/protocol/login.html

ItsGravix commented 7 years ago

@Manevolent I get this: org.json.JSONException: JSONObject["wst:RequestedSecurityToken"] not found.

Erezbiox1 commented 7 years ago

Exception in thread "main" java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 1

Erezbiox1 commented 7 years ago

Can anyone please help me out on this?

Erezbiox1 commented 7 years ago

Simply removing the line from the gist seems to work... weird. the line is "this.cookies.put(setCookie[0], setCookie[1]);"

metasonic commented 6 years ago

@Erezbiox1 any chance you got a fork of this with the fix applied for logging in with email and password or provide a short guide on how to get this working? Thank you!

delthas commented 6 years ago

Hello, I will look into this this week. Sorry for the long delay. To be honest I wasn't sure if anyone needed this at all.

Erezbiox1 commented 6 years ago

@metasonic Yes, here's the gist, and here's the required libraries: image Do note, this only works with Skype4J

metasonic commented 6 years ago

@Erezbiox1 Thanks a lot for that, integrated it locally with Skype4J, tested it and it works, but having issues using the packaged Skype4J in another project. Getting the following error: Exception in thread "main" java.lang.NoSuchMethodError: org.json.JSONArray.forEach(Ljava/util/function/Consumer;)V at com.samczsun.skype4j.internal.client.MSFTSkypeClient$LiveLoginHelper.parsePayload(MSFTSkypeClient.java:206) at com.samczsun.skype4j.internal.client.MSFTSkypeClient$LiveLoginHelper.getXTokenObject(MSFTSkypeClient.java:267) at com.samczsun.skype4j.SkypeBuilder.build(SkypeBuilder.java:134)

After adding the class to the project made the following change to SkypeBuilder `public Skype build() { if (resources.isEmpty()) { throw new IllegalArgumentException("No resources selected"); } if (password != null && !username.contains("@")) { return new FullClient(username, password, resources, customLogger, errorHandlers); } else if (chatId != null && !username.contains("@")) { return new GuestClient(username, chatId, resources, customLogger, errorHandlers); } else if (username.contains("@")) { JSONObject object = null; try { object = MSFTSkypeClient.LiveLoginHelper.getXTokenObject(username, password); } catch (Exception e) { throw new IllegalArgumentException("Bad response"); }

        String skypeToken = object.getString("skypetoken");
        String skypeId = object.getString("skypeid");
        return new MSFTSkypeClient(skypeToken, skypeId,
                resources, customLogger,
                errorHandlers);
    } else {
        throw new IllegalArgumentException("No chat specified");
    }`
metasonic commented 6 years ago

@Delthas the framework you buit is the perfect plug and play not stress that you need for Skype, so, I for one love it and would like to see it grow

delthas commented 6 years ago

Hello. Good news! I have added support for Microsoft accounts to JavaSkype. There are no API changes besides the fact that logging with a Microsoft account (e.g. foo.bar@hotmail.com) should work.

Please update to version 1.0.22 (I have copied the <dependency> block below). Open a new issue for any problem you may have, but do send me the debug logs when opening an issue (simply call setDebug to create a debug file).

    <dependency>       
           <groupId>fr.delthas</groupId>
           <artifactId>javaskype</artifactId>
           <version>1.0.22</version>
    </dependency>
indeterminatus commented 6 years ago

@Delthas thanks for tackling this issue in such a speedy fashion now :). There still seems to be a problem when using a Skype account that has been linked to a Microsoft account (as is the case for me). I can provide two debug logs (one for Skype login, one for Microsoft Account login) and would be quite willing to help resolve this -- kindly contact me via e-mail.

metasonic commented 6 years ago

@Delthas thanks a lot for this!

metasonic commented 6 years ago

After doing the following steps skype.connect(); remains stuck Steps:

  1. create a new skype object
  2. initialize connection (skype.connect();)
  3. get the groups you are into (skype.getGroups(); )
  4. disconnect *Notice that after doing this a few times the script will remain stuck at the skype.connect part PS. sometimes it gives the following error: Exception in thread "Skype-Receiver-Thread" java.lang.IllegalArgumentException at fr.delthas.skype.NotifConnector.parseEntity(NotifConnector.java:792) at fr.delthas.skype.NotifConnector.updateThread(NotifConnector.java:738) at fr.delthas.skype.NotifConnector.processPacket(NotifConnector.java:254) at fr.delthas.skype.NotifConnector.lambda$new$0(NotifConnector.java:73) at java.lang.Thread.run(Thread.java:745)

Debug logs https://www.dropbox.com/s/5mql7cyxs9na9tj/debug3.txt?dl=0 https://www.dropbox.com/s/e6uzyrjos7gfefl/debug2.txt?dl=1