CAT-SOOP API: catsoop.api

Methods related to authentication for API access

View Source

Members

  • catsoop.api.delete_api_token (function, lines 44-53)

    Render an API token unusable

    Parameters:

    • context: the context associated with this request
    • username: the user for whom a key should be generated

 

  • catsoop.api.get_api_tokens (function, lines 56-72)

    List the API tokens currently usable by the given user.

    Parameters:

    • context: the context associated with this request
    • username: the user whose keys we want

    Returns: a (possibly empty) list of API tokens available to the given user

 

  • catsoop.api.get_logged_in_user (function, lines 93-113)

    Helper function. Given a request context, returns the information associated with the user making the request if an API token is present.

    Parameters:

    • context: the context associated with this request

    Returns: a dictionary containing the information associated with the user who holds the given API token; it will contain the key api_token, as well as some subset of the keys 'username', 'name', and 'email'.

 

  • catsoop.api.get_user_information (function, lines 116-210)

    Return the information associated with a user identified by an API token or a username and password.

    Parameters:

    • context: the context associated with this request

    Optional Parameters:

    • uname: if logging in via password, this is the username of the user in question.
    • passwd: if logging in via password, this is the hex-encoded 32-bit result of hashing the user's password with pbkdf2 for 100000 iterations, with a salt given by the username and the password concatenated together. this is not the user's password in plain text.
    • api_token: if logging in via API token, this is the token of the person making the request.
    • course: if given, relevant user information from that course (section, role, permissions, etc) will be included in the result
    • _as: if making this request to get someone else's information, this is the other person's username. must have relevant permissions.

    Returns: a dictionary with two keys. 'ok' maps to a Boolean indicating whether the lookup was successful.

    • If 'ok' maps to False, then the additional key is 'error', which maps to a string containing an error message.
    • If 'ok' maps to True, then the additional key is 'user_info', which maps to a dictionary containing the user's information.

 

  • catsoop.api.new_api_token (function, lines 27-41)

    Create an API token for a user, and store the association in the database.

    Parameters:

    • context: the context associated with this request
    • username: the user for whom a key should be generated

    Returns: the newly-generated API token

 

  • catsoop.api.userinfo_from_token (function, lines 75-90)

    Given an API token, return the associated user's user info.

    Parameters:

    • context: the context associated with this request
    • tok: an API token

    Returns: a dictionary containing basic user information. Returns None if the given token is invalid.