def create_auth_server(): client_store = ClientStore() client_store.add_client( client_id="alexa.matsuoka", client_secret="xxxx", redirect_uris=[ "https://layla.amazon.com/api/skill/link/M2Q7FOC6AVxxxx", "https://pitangui.amazon.com/api/skill/link/M2Q7FOC6AVxxxx", "https://alexa.amazon.co.jp/api/skill/link/M2Q7FOC6AVxxxx" ]) token_store = TokenStore() token_store.save_token( AccessToken(client_id="alexa.matsuoka", grant_type="authorization_code", user_id="*****@*****.**", token="xxxx")) provider = Provider(access_token_store=token_store, auth_code_store=token_store, client_store=client_store, token_generator=Uuid4(), client_authentication_source=http_basic_auth) provider.add_grant( AuthorizationCodeGrant(site_adapter=TestSiteAdapter(), unique_token=True)) app = Application([ url(provider.authorize_path, OAuth2Handler, dict(provider=provider)), url(provider.token_path, OAuth2Handler, dict(provider=provider)), ], debug=False) return app
class MemoryTokenStoreTestCase(unittest.TestCase): def setUp(self): self.access_token_data = {"client_id": "myclient", "token": "xyz", "scopes": ["foo_read", "foo_write"], "data": {"name": "test"}, "grant_type": "authorization_code"} self.auth_code = AuthorizationCode("myclient", "abc", 100, "http://localhost", ["foo_read", "foo_write"], {"name": "test"}) self.test_store = TokenStore() def test_fetch_by_code(self): with self.assertRaises(AuthCodeNotFound): self.test_store.fetch_by_code("unknown") def test_save_code_and_fetch_by_code(self): success = self.test_store.save_code(self.auth_code) self.assertTrue(success) result = self.test_store.fetch_by_code(self.auth_code.code) self.assertEqual(result, self.auth_code) def test_save_token_and_fetch_by_token(self): access_token = AccessToken(**self.access_token_data) success = self.test_store.save_token(access_token) self.assertTrue(success) result = self.test_store.fetch_by_token(access_token.token) self.assertEqual(result, access_token)
class MemoryTokenStoreTestCase(unittest.TestCase): def setUp(self): self.access_token_data = { "client_id": "myclient", "token": "xyz", "scopes": ["foo_read", "foo_write"], "data": { "name": "test" }, "grant_type": "authorization_code" } self.auth_code = AuthorizationCode("myclient", "abc", 100, "http://localhost", ["foo_read", "foo_write"], {"name": "test"}) self.test_store = TokenStore() def test_fetch_by_code(self): with self.assertRaises(AuthCodeNotFound): self.test_store.fetch_by_code("unknown") def test_save_code_and_fetch_by_code(self): success = self.test_store.save_code(self.auth_code) self.assertTrue(success) result = self.test_store.fetch_by_code(self.auth_code.code) self.assertEqual(result, self.auth_code) def test_save_token_and_fetch_by_token(self): access_token = AccessToken(**self.access_token_data) success = self.test_store.save_token(access_token) self.assertTrue(success) result = self.test_store.fetch_by_token(access_token.token) self.assertEqual(result, access_token)