Skip to content

Commit

Permalink
Merge pull request #2 from louis-e/master
Browse files Browse the repository at this point in the history
 Added bearer token authentication method
  • Loading branch information
ChillerDragon authored Mar 12, 2024
2 parents fa2f922 + eaf453e commit 764542b
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 764542b

Please sign in to comment.