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

Added bearer token authentication method #185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions quarry/net/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import sys
import requests

from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from twisted.internet import defer
Expand Down Expand Up @@ -160,6 +161,14 @@ def from_file(cls, display_name=None, uuid=None, profiles_path=None):
return cls.from_token(client_token, access_token,
p_display_name, p_uuid)

@classmethod
def from_bearer_token(cls, bearer_token):
headers = {'Authorization': f'Bearer {bearer_token}'}
response = requests.get("https://api.minecraftservices.com/minecraft/profile", headers=headers).json()
player_uuid = UUID.from_hex(response['id'])
player_username = response['name']
return Profile('(skip)', bearer_token, player_username, player_uuid)

@classmethod
def _from_response(cls, response):
return cls(
Expand Down Expand Up @@ -214,6 +223,12 @@ def make_parser(cls, parser=None):
help="Sets the offline display name to use. If none of these "
"options are given, quarry uses 'quarry' as an offline "
"display name.")
group.add_argument(
"--bearer-token",
metavar="BEARER_TOKEN",
help="Logs in using a bearer token. This is used by the official "
"client to log in to a Microsoft account."
"See https://kqzz.github.io/mc-bearer-token/ for more info.")
return parser

@classmethod
Expand All @@ -223,6 +238,8 @@ def make_profile(cls, args):
return Profile.from_credentials(email, password)
if args.session_name:
return Profile.from_file(args.session_name)
if args.bearer_token:
return Profile.from_bearer_token(args.bearer_token)
return defer.succeed(
OfflineProfile.from_display_name(args.offline_name or "quarry"))

Expand Down