예제 #1
0
파일: views.py 프로젝트: thousandeyes/lemur
    def post(self, data=None):
        """
        .. http:post:: /keys

           Creates an API Key.

           **Example request**:

           .. sourcecode:: http

              POST /keys HTTP/1.1
              Host: example.com
              Accept: application/json, text/javascript

              {
                "name": "my custom name",
                "user_id": 1,
                "ttl": -1
              }

           **Example response**:

           .. sourcecode:: http

              HTTP/1.1 200 OK
              Vary: Accept
              Content-Type: text/javascript

              {

                "jwt": ""
              }

           :reqheader Authorization: OAuth token to authenticate
           :statuscode 200: no error
           :statuscode 403: unauthenticated
        """
        if not ApiKeyCreatorPermission().can():
            if data["user"]["id"] != g.current_user.id:
                return (
                    dict(
                        message="You are not authorized to create tokens for: {0}".format(
                            data["user"]["username"]
                        )
                    ),
                    403,
                )

        access_token = service.create(
            name=data["name"],
            user_id=data["user"]["id"],
            ttl=data["ttl"],
            revoked=False,
            issued_at=int(datetime.utcnow().timestamp()),
        )
        return dict(
            jwt=create_token(access_token.user_id, access_token.id, access_token.ttl)
        )
예제 #2
0
파일: cli.py 프로젝트: Netflix/lemur
def create(uid, name, ttl):
    """
    Create a new api key for a user.
    :return:
    """
    print("[+] Creating a new api key.")
    key = api_key_service.create(user_id=uid, name=name,
        ttl=ttl, issued_at=int(datetime.utcnow().timestamp()), revoked=False)
    print("[+] Successfully created a new api key. Generating a JWT...")
    jwt = create_token(uid, key.id, key.ttl)
    print("[+] Your JWT is: {jwt}".format(jwt=jwt))
예제 #3
0
def create(uid, name, ttl):
    """
    Create a new api key for a user.
    :return:
    """
    print("[+] Creating a new api key.")
    key = api_key_service.create(user_id=uid,
                                 name=name,
                                 ttl=ttl,
                                 issued_at=int(datetime.utcnow().timestamp()),
                                 revoked=False)
    print("[+] Successfully created a new api key. Generating a JWT...")
    jwt = create_token(uid, key.id, key.ttl)
    print("[+] Your JWT is: {jwt}".format(jwt=jwt))
예제 #4
0
파일: views.py 프로젝트: Netflix/lemur
    def post(self, data=None):
        """
        .. http:post:: /keys

           Creates an API Key.

           **Example request**:

           .. sourcecode:: http

              POST /keys HTTP/1.1
              Host: example.com
              Accept: application/json, text/javascript

              {
                "name": "my custom name",
                "user_id": 1,
                "ttl": -1
              }

           **Example response**:

           .. sourcecode:: http

              HTTP/1.1 200 OK
              Vary: Accept
              Content-Type: text/javascript

              {

                "jwt": ""
              }

           :reqheader Authorization: OAuth token to authenticate
           :statuscode 200: no error
           :statuscode 403: unauthenticated
        """
        if not ApiKeyCreatorPermission().can():
            if data['user']['id'] != g.current_user.id:
                return dict(message="You are not authorized to create tokens for: {0}".format(data['user']['username'])), 403

        access_token = service.create(name=data['name'], user_id=data['user']['id'], ttl=data['ttl'],
                                      revoked=False, issued_at=int(datetime.utcnow().timestamp()))
        return dict(jwt=create_token(access_token.user_id, access_token.id, access_token.ttl))