class TestAuthClientAuthorizeToken(unittest.TestCase): server_url = TEST_SERVER_URL def setUp(self): self.client = Client("abc", "xyz", server_url=self.server_url) responses.add(responses.POST, 'https://server/v1/authorization', body='{"access_token": "izatoken"}', content_type='application/json') @responses.activate def test_authorize_token_with_default_arguments(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion) self.assertEquals(token, "izatoken") req_body = json.loads(responses.calls[0].request.body) self.assertEquals( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "response_type": "token", }) @responses.activate def test_authorize_token_with_explicit_scope(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, scope="storage") self.assertEquals(token, "izatoken") req_body = json.loads(responses.calls[0].request.body) self.assertEquals( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "response_type": "token", "scope": "storage", }) @responses.activate def test_authorize_token_with_explicit_client_id(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, client_id="cba") self.assertEquals(token, "izatoken") req_body = json.loads(responses.calls[0].request.body) self.assertEquals( req_body, { "assertion": assertion, "client_id": "cba", "state": "x", "response_type": "token", })
class TestAuthClientAuthorizeToken(unittest.TestCase): server_url = TEST_SERVER_URL def setUp(self): self.client = Client("abc", "xyz", server_url=self.server_url) responses.add(responses.POST, 'https://server/v1/authorization', body='{"access_token": "izatoken"}', content_type='application/json') @responses.activate def test_authorize_token_with_default_arguments(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion) self.assertEquals(token, "izatoken") req_body = json.loads(responses.calls[0].request.body) self.assertEquals(req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "response_type": "token", }) @responses.activate def test_authorize_token_with_explicit_scope(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, scope="storage") self.assertEquals(token, "izatoken") req_body = json.loads(responses.calls[0].request.body) self.assertEquals(req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "response_type": "token", "scope": "storage", }) @responses.activate def test_authorize_token_with_explicit_client_id(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, client_id="cba") self.assertEquals(token, "izatoken") req_body = json.loads(responses.calls[0].request.body) self.assertEquals(req_body, { "assertion": assertion, "client_id": "cba", "state": "x", "response_type": "token", })
def get_oauth_token(client_id=CLIENT_ID, oauth_server=OAUTH_SERVER, auth_server=AUTH_SERVER, email=EMAIL, password=PASSWORD): if password is None: raise Exception('You must set FXA_PASSWORD') print('Getting an oauth token from FxA') oauth_client = OAuthClient(client_id, server_url=oauth_server) session = Client(server_url=auth_server).login(email, password=password) assertion = session.get_identity_assertion(oauth_server) return oauth_client.authorize_token(assertion, scope="profile")
def get_oauth_token(client_id=CLIENT_ID, oauth_server=OAUTH_SERVER, auth_server=AUTH_SERVER, email=EMAIL, password=PASSWORD): if password is None: raise Exception('You must set FXA_PASSWORD') print('Getting an oauth token from FxA') oauth_client = OAuthClient(client_id, server_url=oauth_server) session = Client(server_url=auth_server).login(email, password=password) assertion = session.get_identity_assertion(oauth_server) return oauth_client.authorize_token(assertion, scope="profile")
class TestAuthClientAuthorizeToken(unittest.TestCase): server_url = TEST_SERVER_URL def setUp(self): self.client = Client("abc", "xyz", server_url=self.server_url) responses.add(responses.POST, 'https://server/v1/authorization', body='{"access_token": "izatoken"}', content_type='application/json') add_jwks_response() @responses.activate def test_authorize_token_with_default_arguments(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion) self.assertEqual(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEqual( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": AnyStringValue(), "response_type": "token", }) @responses.activate def test_authorize_token_with_explicit_scope(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, scope="storage") self.assertEqual(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEqual( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": AnyStringValue(), "response_type": "token", "scope": "storage", }) @responses.activate def test_authorize_token_with_explicit_client_id(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, client_id="cba") self.assertEqual(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEqual( req_body, { "assertion": assertion, "client_id": "cba", "state": AnyStringValue(), "response_type": "token", }) @responses.activate def test_authorize_token_with_session_object(self): session = mock.Mock() session.get_identity_assertion.return_value = "IDENTITY" token = self.client.authorize_token(session) session.get_identity_assertion.assert_called_once_with( audience=TEST_SERVER_URL, service=self.client.client_id) self.assertEqual(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEqual( req_body, { "assertion": "IDENTITY", "client_id": self.client.client_id, "state": AnyStringValue(), "response_type": "token", })