def fetch_by_code(self, code): code_data = self.collection.find_one({"code": code}) if code_data is None: raise AuthCodeNotFound return AuthorizationCode(client_id=code_data.get("client_id"), code=code_data.get("code"), expires_at=code_data.get("expires_at"), redirect_uri=code_data.get("redirect_uri"), scopes=code_data.get("scopes"), data=code_data.get("data"), user_id=code_data.get("user_id"))
def fetch_by_code(self, code): """ Returns data belonging to an authorization code from redis or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`. """ code_data = self.read(code) if code_data is None: raise AuthCodeNotFound return AuthorizationCode(**code_data)
def fetch_by_code(self, code): """ Returns data belonging to an authorization code from memcache or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`. """ code_data = self.mc.get(self._generate_cache_key(code)) if code_data is None: raise AuthCodeNotFound return AuthorizationCode(**code_data)
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 process(self, request, response, environ): """ Generates a new authorization token. A form to authorize the access of the application can be displayed with the help of `oauth2.web.SiteAdapter`. """ data = self.authorize(request, response, environ, self.scope_handler.scopes) if isinstance(data, Response): print "?" print "?" print "?" print "?" print "?" print "?" print "?" print "?" print "?" print data return data code = self.token_generator.generate() expires = int(time.time()) + self.token_expiration auth_code = AuthorizationCode(client_id=self.client.identifier, code=code, expires_at=expires, redirect_uri=self.client.redirect_uri, scopes=self.scope_handler.scopes, data=data[0], user_id=data[1]) self.auth_code_store.save_code(auth_code) response.add_header("Location", self._generate_location(code)) response.body = "" response.status_code = 302 return response
def fetch_by_code(self, code): """ Returns an AuthorizationCode fetched from a storage. :param code: The authorization code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`oauth2.error.AuthCodeNotFound` if no data could be retrieved for given code. """ orm_code = (self.db.query(orm.OAuthCode).filter_by(code=code).first()) if orm_code is None: raise AuthCodeNotFound() else: return AuthorizationCode( client_id=orm_code.client_id, code=code, expires_at=orm_code.expires_at, redirect_uri=orm_code.redirect_uri, scopes=[], user_id=orm_code.user_id, data={'session_id': orm_code.session_id}, )
def test_save_code(self): data = { "client_id": "myclient", "code": "abc", "expires_at": 100, "redirect_uri": "http://localhost", "scopes": ["foo_read", "foo_write"], "data": { "name": "test" }, "user_id": 1 } auth_code = AuthorizationCode(**data) cache_key = self._generate_test_cache_key(data["code"]) mc_mock = Mock(spec=["set"]) store = TokenStore(mc=mc_mock, prefix=self.cache_prefix) store.save_code(auth_code) mc_mock.set.assert_called_with(cache_key, data)