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

Integrate Authentication for Microsoft Accounts #788

Merged
merged 12 commits into from
Dec 11, 2020
Merged

Integrate Authentication for Microsoft Accounts #788

merged 12 commits into from
Dec 11, 2020

Conversation

kashalls
Copy link
Contributor

@kashalls kashalls commented Dec 11, 2020

This pull request adds two new npm modules: @xboxreplay/xboxlive-auth and node-fetch
This integrates logging into Minecraft Servers for Microsoft Accounts.
In order to log into a server using a microsoft account, you must specify options.auth = 'microsoft';

This fixes:
#782
PrismarineJS/mineflayer#1480

// todo: clean up code just a little bit more.

src/client/encrypt.js Outdated Show resolved Hide resolved
Copy link
Contributor

@Karang Karang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rom1504
Copy link
Member

rom1504 commented Dec 11, 2020

Does it work ? Does it fake the browser ?
Can you update API.md with information on how to use it ?

@kashalls
Copy link
Contributor Author

Does it work ? Does it fake the browser ?
Can you update API.md with information on how to use it ?

It works, valid session and everything. Any requests to minecraftservices.com uses a simple user-agent, requests made to Xbox Live uses this User-Agent: Mozilla/5.0 (XboxReplay; XboxLiveAuth/3.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

2FA is not supported with this method as it causes authentication issues, however this can be used to temporarily support it until a better solution is found.

@kashalls
Copy link
Contributor Author

Can you update API.md with information on how to use it ?
I can, do you want me to create an example on how to use it with Microsoft Authentication?

@rom1504
Copy link
Member

rom1504 commented Dec 11, 2020

Yes, basically add the auth option in API.md, and a simple example is useful in the examples folder

@rom1504
Copy link
Member

rom1504 commented Dec 11, 2020

Thanks, that's great.
Could you also add a small note about the existence of this auth option in https://github.com/PrismarineJS/node-minecraft-protocol#echo-client-example ?
I think that lot of users will be asking about that and we want to make it as visible as possible

@rom1504
Copy link
Member

rom1504 commented Dec 11, 2020

LGTM, we probably want to support the json storage here too, but this can be done in another PR

@rom1504 rom1504 merged commit 5d723e9 into PrismarineJS:master Dec 11, 2020
@kashalls
Copy link
Contributor Author

LGTM, we probably want to support the json storage here too, but this can be done in another PR

Afaik, we do not have enough information to support the launcher_accounts.json file. We definitely could do the same thing for Mojang Auth though.

@rom1504
Copy link
Member

rom1504 commented Dec 11, 2020

What information are we missing ? Can't we store the tokens ?

matthi4s pushed a commit to aternosorg/node-minecraft-protocol that referenced this pull request Jun 9, 2021
* add node-fetch and @xboxreplay/xboxlive-auth for microsoft/xbox auth

* decide which authentication to use based on options;

if options.auth === 'microsoft' then use microsoft/xbox auth, else use Yggdrasil until they kill that.

* push working auth

* commentary

* eslint does not like me :(

* User-Agent works just fine without version

* linting = 95% of development

* revert changes to encrypt.js

* set haveCredentials to whether or not we have a token.

Technically this will always be true so...?

* eslint

* mod+create: api + example

* mod: readme.md
@craftycram
Copy link

craftycram commented Dec 18, 2023

Is there a way to use an already valid access token to authenticate the user?

I have a web dashboard where I'm logging in using Microsoft Oauth with the XboxLive.signin scope. I want to use the access_token from there to create a minecraft client in the backend. That's why just using the already existing token, instead of using https://www.microsoft.com/link would be awesome.

EDIT: found your discord server and posted the question there as well. not sure if comments on three year old PR still get noticed

@kashalls
Copy link
Contributor Author

Is there a way to use an already valid access token to authenticate the user?

I have a web dashboard where I'm logging in using Microsoft Oauth with the XboxLive.signin scope. I want to use the access_token from there to create a minecraft client in the backend. That's why just using the already existing token, instead of using https://www.microsoft.com/link would be awesome.

EDIT: found your discord server and posted the question there as well. not sure if comments on three year old PR still get noticed

Afaik its been done, you just need to provide your own auth factory. Theres been some mentions in the discord on how to do this.

@craftycram
Copy link

As far as I understood browsing through the code doing the authentication flows normally I would need to fork prismarine-auth, since the flows are defined there right?
There is no way for me to provide custom flows with minecraft-protocol client options directly, if I got that correctly.
@kashalls

@kashalls
Copy link
Contributor Author

As far as I understood browsing through the code doing the authentication flows normally I would need to fork prismarine-auth, since the flows are defined there right? There is no way for me to provide custom flows with minecraft-protocol client options directly, if I got that correctly. @kashalls

https://github.com/PrismarineJS/prismarine-auth/blob/master/src/MicrosoftAuthFlow.js#L54

The auth flow allows you to use a function instead of a caching location, allowing you to use external means of authentication.
Ex: https://discord.com/channels/413438066984747026/1127636567914184826

You can just replicate the data that prismarine-auth generates and store it like that. You can also try switching the auth provider to the old Yggdrasil one, setting all of the session data required and then setting the bot to offline mode. I haven't tried that in a bit however.

I have a web dashboard where I'm logging in using Microsoft Oauth with the XboxLive.signin scope. I want to use the access_token from there to create a minecraft client in the backend. That's why just using the already existing token

I would honestly save that token into a database that can be fetched using a cacheFactory like I posted a link of an example. It would make it easier.

@craftycram
Copy link

Aight thanks. Imma look into that later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants