function createOrRetrieveAuth(
        $username,
        $password,
        callable $enterPasswordCallback,
        $scopes,
        $note,
        $noteURL = "http://www.github.com/danack/GithubArtaxService",
        $maxAttempts = 3
    ) {
        $basicToken = new BasicAuthToken($username, $password);
        $otp = false;

        for ($i = 0; $i < $maxAttempts; $i++) {
            try {
                $createAuthToken = $this->createAuthorization(
                    $basicToken->__toString(),
                    $scopes,
                    $note
                );

                $createAuthToken->setNote_url($noteURL);
                if ($otp) {
                    $createAuthToken->setOtp($otp);
                }
                $authResult = $createAuthToken->execute();

                return $authResult;
            }
            catch (OneTimePasswordAppException $otpae) {
                $otp = $enterPasswordCallback(
                    "Please enter the code from your 2nd factor auth app:"
                );
            }
            catch (OneTimePasswordSMSException $otse) {
                $otp = $enterPasswordCallback(
                    "Please enter the code from the SMS Github should have sent you:"
                );
            }
        }

        throw new GithubArtaxServiceException("Failed to create or retrieve oauth token.");
    }