Ejemplo n.º 1
0
async def auth_mgr(event_loop):
    session = ClientSession(loop=event_loop)
    mgr = AuthenticationManager(session, "abc", "123", "http://localhost")
    mgr.oauth = OAuth2TokenResponse.parse_raw(get_response("auth_oauth2_token"))
    mgr.user_token = XAUResponse.parse_raw(get_response("auth_user_token"))
    mgr.xsts_token = XSTSResponse.parse_raw(get_response("auth_xsts_token"))
    yield mgr
    await session.close()
Ejemplo n.º 2
0
async def auth_mgr(event_loop):
    mgr = AuthenticationManager(
        ClientSession(loop=event_loop), "abc", "123", "http://localhost"
    )
    mgr.oauth = OAuth2TokenResponse.parse_raw(get_response("auth_oauth2_token"))
    mgr.user_token = XAUResponse.parse_raw(get_response("auth_user_token"))
    mgr.xsts_token = XSTSResponse.parse_raw(get_response("auth_xsts_token"))
    return mgr
Ejemplo n.º 3
0
 async def _oauth2_token_request(self, data: dict) -> OAuth2TokenResponse:
     """Execute token requests."""
     data["client_id"] = self._client_id
     if self._client_secret:
         data["client_secret"] = self._client_secret
     resp = await self.session.post(
         "https://login.live.com/oauth20_token.srf", data=data)
     # print(await resp.content.read())
     resp.raise_for_status()
     return OAuth2TokenResponse.parse_raw(await resp.text())
Ejemplo n.º 4
0
async def async_main():
    parser = argparse.ArgumentParser(description="Change your gamertag")
    parser.add_argument(
        "--tokens",
        "-t",
        default=TOKENS_FILE,
        help=f"Token filepath. Default: '{TOKENS_FILE}'",
    )
    parser.add_argument(
        "--client-id",
        "-cid",
        default=os.environ.get("CLIENT_ID", CLIENT_ID),
        help="OAuth2 Client ID",
    )
    parser.add_argument(
        "--client-secret",
        "-cs",
        default=os.environ.get("CLIENT_SECRET", CLIENT_SECRET),
        help="OAuth2 Client Secret",
    )

    args = parser.parse_args()

    if not os.path.exists(args.tokens):
        print("No token file found, run xbox-authenticate")
        sys.exit(-1)

    async with ClientSession() as session:
        auth_mgr = AuthenticationManager(
            session, args.client_id, args.client_secret, ""
        )

        with open(args.tokens, mode="r") as f:
            tokens = f.read()
        auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
        try:
            await auth_mgr.refresh_tokens()
        except ClientResponseError:
            print("Could not refresh tokens")
            sys.exit(-1)

        with open(args.tokens, mode="w") as f:
            f.write(auth_mgr.oauth.json())

        xbl_client = XboxLiveClient(auth_mgr)

        try:
            resp = await xbl_client.people.get_friends_own()
        except ClientResponseError:
            print("Invalid HTTP response")
            sys.exit(-1)

        pprint(resp.dict())
Ejemplo n.º 5
0
async def async_main(client_id: str, client_secret: str, redirect_uri: str,
                     token_filepath: str):

    async with ClientSession() as session:
        auth_mgr = AuthenticationManager(session, client_id, client_secret,
                                         redirect_uri)

        # Refresh tokens if we have them
        if os.path.exists(token_filepath):
            with open(token_filepath, mode="r") as f:
                tokens = f.read()
            auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
            await auth_mgr.refresh_tokens()

        # Request new ones if they are not valid
        if not (auth_mgr.xsts_token and auth_mgr.xsts_token.is_valid()):
            auth_url = auth_mgr.generate_authorization_url()
            webbrowser.open(auth_url)
            code = await queue.get()
            await auth_mgr.request_tokens(code)

        with open(token_filepath, mode="w") as f:
            f.write(auth_mgr.oauth.json())
Ejemplo n.º 6
0
async def do_authentication(args: argparse.Namespace) -> AuthenticationManager:
    """
    Shortcut for doing xbox live authentication (uses xbox-webapi-python lib).

    Args:
        args: Parsed arguments

    Returns: An authenticated instance of AuthenticationManager

    Raises:
        AuthenticationException: If authentication failed
    """
    async with aiohttp.ClientSession() as session:
        auth_mgr = AuthenticationManager(
            session, args.client_id, args.client_secret, args.redirect_uri
        )

        # Refresh tokens if we have them
        if os.path.exists(args.tokens):
            with open(args.tokens, mode="r") as f:
                tokens = f.read()
            auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
            await auth_mgr.refresh_tokens()

        # Request new ones if they are not valid
        if not (auth_mgr.xsts_token and auth_mgr.xsts_token.is_valid()):
            auth_url = auth_mgr.generate_authorization_url()
            print(f'Authorize with following URL: {auth_url}\n')

            code = input('Enter received authorization code: ')
            await auth_mgr.request_tokens(code)

        with open(args.tokens, mode="w") as f:
            f.write(auth_mgr.oauth.json())

    return auth_mgr
async def async_main():
    parser = argparse.ArgumentParser(description="Change your gamertag")
    parser.add_argument(
        "--tokens",
        "-t",
        default=TOKENS_FILE,
        help=f"Token filepath. Default: '{TOKENS_FILE}'",
    )
    parser.add_argument(
        "--client-id",
        "-cid",
        default=os.environ.get("CLIENT_ID", CLIENT_ID),
        help="OAuth2 Client ID",
    )
    parser.add_argument(
        "--client-secret",
        "-cs",
        default=os.environ.get("CLIENT_SECRET", CLIENT_SECRET),
        help="OAuth2 Client Secret",
    )
    parser.add_argument("gamertag", help="Desired Gamertag")

    args = parser.parse_args()

    if len(args.gamertag) > 15:
        print("Desired gamertag exceedes limit of 15 chars")
        sys.exit(-1)

    if not os.path.exists(args.tokens):
        print("No token file found, run xbox-authenticate")
        sys.exit(-1)

    async with ClientSession() as session:
        auth_mgr = AuthenticationManager(session, args.client_id,
                                         args.client_secret, "")

        with open(args.tokens, mode="r") as f:
            tokens = f.read()
        auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
        try:
            await auth_mgr.refresh_tokens()
        except ClientResponseError:
            print("Could not refresh tokens")
            sys.exit(-1)

        with open(args.tokens, mode="w") as f:
            f.write(auth_mgr.oauth.json())

        xbl_client = XboxLiveClient(auth_mgr)

        print(":: Trying to change gamertag to '%s' for xuid '%i'..." %
              (args.gamertag, xbl_client.xuid))

        print("Claiming gamertag...")
        try:
            resp = await xbl_client.account.claim_gamertag(
                xbl_client.xuid, args.gamertag)
            if resp == ClaimGamertagResult.NotAvailable:
                print(
                    "Claiming gamertag failed - Desired gamertag is unavailable"
                )
                sys.exit(-1)
        except ClientResponseError:
            print("Invalid HTTP response from claim")
            sys.exit(-1)

        print("Changing gamertag...")
        try:
            resp = await xbl_client.account.change_gamertag(
                xbl_client.xuid, args.gamertag)
            if resp == ChangeGamertagResult.NoFreeChangesAvailable:
                print("Changing gamertag failed - You are out of free changes")
                sys.exit(-1)
        except ClientResponseError:
            print("Invalid HTTP response from change")
            sys.exit(-1)

        print("Gamertag successfully changed to %s" % args.gamertag)
Ejemplo n.º 8
0
async def async_main():
    parser = argparse.ArgumentParser(description="Change your gamertag")
    parser.add_argument(
        "--tokens",
        "-t",
        default=TOKENS_FILE,
        help=f"Token filepath. Default: '{TOKENS_FILE}'",
    )
    parser.add_argument(
        "--client-id",
        "-cid",
        default=os.environ.get("CLIENT_ID", CLIENT_ID),
        help="OAuth2 Client ID",
    )
    parser.add_argument(
        "--client-secret",
        "-cs",
        default=os.environ.get("CLIENT_SECRET", CLIENT_SECRET),
        help="OAuth2 Client Secret",
    )

    args = parser.parse_args()

    if not os.path.exists(args.tokens):
        print("No token file found, run xbox-authenticate")
        sys.exit(-1)

    async with ClientSession() as session:
        auth_mgr = AuthenticationManager(
            session, args.client_id, args.client_secret, ""
        )

        with open(args.tokens, mode="r") as f:
            tokens = f.read()
        auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
        try:
            await auth_mgr.refresh_tokens()
        except ClientResponseError:
            print("Could not refresh tokens")
            sys.exit(-1)

        with open(args.tokens, mode="w") as f:
            f.write(auth_mgr.oauth.json())

        xbl_client = XboxLiveClient(auth_mgr)

        try:
            uniname = "c:/users/willr/downloads/UNIQUENAME9.mp4"
            # resp = await xbl_client.screenshots.get_recent_own_screenshots(max_items=3)
            resp = await xbl_client.gameclips.get_recent_own_clips(max_items=1)
            # downloadLink = resp.game_clips[0].game_clip_uris[0].uri
            # wget.download(downloadLink, uniname)
            # clip = VideoFileClip(uniname).subclip(8)
            # clip.write_videofile("c:/users/willr/downloads/UNIQUENAME9-finished.mp4",temp_audiofile='temp-audio.m4a', remove_temp=True, codec="libx264", audio_codec="aac")
            # clip.close()
            # highlightz = TweetMachine()
            # highlightz.makeAVidTweet('c:/users/willr/downloads/UNIQUENAME9-finished.mp4','🚨🚨🚨BUZZER BEATER ALERT🚨🚨🚨')
        except ClientResponseError:
            print("Invalid HTTP response")
            sys.exit(-1)

        pprint(resp.dict())