Ejemplo n.º 1
0
    def test_response_type_supported(self):
        client = Client(identifier="abc",
                        secret="xyz",
                        authorized_response_types=["test_response_type"])

        self.assertTrue(client.response_type_supported("test_response_type"))
        self.assertFalse(client.response_type_supported("unknown"))
Ejemplo n.º 2
0
    def fetch_by_client_id(self, client_id):
        client_data = self.collection.find_one({"identifier": client_id})

        if client_data is None:
            raise ClientNotFoundError

        return Client(identifier=client_data.get("identifier"),
                      secret=client_data.get("secret"),
                      redirect_uris=client_data.get("redirect_uris"))
Ejemplo n.º 3
0
    def fetch_by_client_id(self, client_id):
        client_data = self.read(client_id)

        if client_data is None:
            raise ClientNotFoundError

        return Client(identifier=client_data["identifier"],
                      secret=client_data["secret"],
                      redirect_uris=client_data["redirect_uris"],
                      authorized_grants=client_data["authorized_grants"],
                      authorized_response_types=client_data["authorized_response_types"])
Ejemplo n.º 4
0
    def test_redirect_uri(self):
        client = Client(identifier="abc",
                        secret="xyz",
                        redirect_uris=["http://callback"])

        self.assertEqual(client.redirect_uri, "http://callback")
        client.redirect_uri = "http://callback"
        self.assertEqual(client.redirect_uri, "http://callback")

        with self.assertRaises(RedirectUriUnknown):
            client.redirect_uri = "http://another.callback"
Ejemplo n.º 5
0
    def setUp(self):
        self.client = Client(identifier="abc",
                             secret="xyz",
                             authorized_grants=["authorization_code"],
                             authorized_response_types=["code"],
                             redirect_uris=["http://callback"])
        self.client_store_mock = Mock(spec=ClientStore)

        self.source_mock = Mock()

        self.authenticator = ClientAuthenticator(
            client_store=self.client_store_mock, source=self.source_mock)
Ejemplo n.º 6
0
    def add_client(self, client_id, client_secret, redirect_uris):
        """
        Add a client app.
        
        :param client_id: Identifier of the client app.
        :param client_secret: Secret the client app uses for authentication
                              against the OAuth 2.0 provider.
        :param redirect_uris: A ``list`` of URIs to redirect to.
        
        """
        self.clients[client_id] = Client(identifier=client_id,
                                         secret=client_secret,
                                         redirect_uris=redirect_uris)

        return True
Ejemplo n.º 7
0
    def fetch_by_client_id(self, client_id):
        """Retrieve a client by its identifier.

        :param client_id: Identifier of a client app.
        :return: An instance of :class:`oauth2.datatype.Client`.
        :raises: :class:`oauth2.error.ClientNotFoundError` if no data could be retrieved for
                 given client_id.
        """
        orm_client = (self.db.query(
            orm.OAuthClient).filter_by(identifier=client_id).first())
        if orm_client is None:
            raise ClientNotFoundError()
        return Client(
            identifier=client_id,
            redirect_uris=[orm_client.redirect_uri],
            secret=HashComparable(orm_client.secret),
        )
Ejemplo n.º 8
0
    def fetch_by_client_id(self, client_id):
        """
        Retrieves a client by its identifier.

        :param client_id: The identifier of a client.

        :return: An instance of :class:`oauth2.datatype.Client`.

        :raises: :class:`oauth2.error.ClientError` if no client could be
                 retrieved.
        """
        grants = None
        redirect_uris = None
        response_types = None

        client_data = self.fetchone(self.fetch_client_query, client_id)

        if client_data is None:
            raise ClientNotFoundError

        grant_data = self.fetchall(self.fetch_grants_query, client_data[0])
        if grant_data:
            grants = []
            for grant in grant_data:
                grants.append(grant[0])

        redirect_uris_data = self.fetchall(self.fetch_redirect_uris_query,
                                           client_data[0])
        if redirect_uris_data:
            redirect_uris = []
            for redirect_uri in redirect_uris_data:
                redirect_uris.append(redirect_uri[0])

        response_types_data = self.fetchall(self.fetch_response_types_query,
                                            client_data[0])
        if response_types_data:
            response_types = []
            for response_type in response_types_data:
                response_types.append(response_type[0])

        return Client(identifier=client_data[1], secret=client_data[2],
                      authorized_grants=grants,
                      authorized_response_types=response_types,
                      redirect_uris=redirect_uris)
Ejemplo n.º 9
0
 def fetch_by_client_id(self, client_id):
     auth_client = AuthClient.get(oauth_id=client_id, get_first=True)
     if auth_client:
         return Client(identifier=auth_client.oauth_id,
                       secret=auth_client.oauth_secret)
     raise ClientNotFoundError