Skip to content

Authentication

Bases: TMDB

Authentication functionality.

https://developers.themoviedb.org/3/authentication

https://www.themoviedb.org/documentation/api/sessions

Source code in src/tmdb_client_py/account.py
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
class Authentication(TMDB):
    """
    Authentication functionality.

    See: https://developers.themoviedb.org/3/authentication
         https://www.themoviedb.org/documentation/api/sessions
    """

    BASE_PATH = "authentication"
    URLS = {
        "guest_session_new": "/guest_session/new",
        "token_new": "/token/new",
        "session_new": "/session/new",
        "token_validate_with_login": "/token/validate_with_login",
        "session_delete": "/session",
    }

    def guest_session_new(self, **kwargs):
        """
        This method will let you create a new guest session. Guest sessions
        are a type of session that will let a user rate movies and TV shows
        but not require them to have a TMDb user account. More
        information about user authentication can be found here
        (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

        Please note, you should only generate a single guest session per
        user (or device) as you will be able to attach the ratings to a
        TMDb user account in the future. There is also IP limits in place
        so you should always make sure it's the end user doing the guest
        session actions.

        If a guest session is not used for the first time within 24 hours,
        it will be automatically deleted.

        Args:

        Returns:
            A dict representation of the JSON returned from the API.
        """
        path = self._get_path("guest_session_new")

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

    def token_new(self, **kwargs):
        """
        Create a temporary request token that can be used to validate a TMDb
        user login. More details about how this works can be found here
        (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

        Args:

        Returns:
            A dict representation of the JSON returned from the API.
        """
        path = self._get_path("token_new")

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

    def session_new(self, **kwargs):
        """
        You can use this method to create a fully valid session ID once a user
        has validated the request token. More information about how this works
        can be found here
        (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

        Args:
            request_token: The token you generated for the user to approve.
                           The token needs to be approved before being
                           used here.

        Returns:
            A dict representation of the JSON returned from the API.
        """
        path = self._get_path("session_new")

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

    def token_validate_with_login(self, **kwargs):
        """
        This method allows an application to validate a request token by entering
        a username and password.

        Not all applications have access to a web view so this can be used as a
        substitute.

        Please note, the preferred method of validating a request token is to
        have a user authenticate the request via the TMDb website. You can read
        about that method here
        (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

        If you decide to use this method please use HTTPS.

        Args:
            username: The user's username on TMDb.
            password: The user's password on TMDb.
            request_token: The token you generated for the user to approve.

        Returns:
            A dict representation of the JSON returned from the API.
        """
        path = self._get_path("token_validate_with_login")

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

    def session_delete(self, **kwargs):
        """
        If you would like to delete (or "logout") from a session, call this
        method with a valid session ID.

        Args:

        Returns:
            A dict representation of the JSON returned from the API.
        """
        path = self._get_path("session_delete")

        payload = {
            "session_id": kwargs.pop("session_id", None),
        }

        response = self._DELETE(path, kwargs, payload)
        self._set_attrs_to_values(response)
        return response

guest_session_new(**kwargs)

This method will let you create a new guest session. Guest sessions are a type of session that will let a user rate movies and TV shows but not require them to have a TMDb user account. More information about user authentication can be found here (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

Please note, you should only generate a single guest session per user (or device) as you will be able to attach the ratings to a TMDb user account in the future. There is also IP limits in place so you should always make sure it's the end user doing the guest session actions.

If a guest session is not used for the first time within 24 hours, it will be automatically deleted.

Args:

Returns:

Type Description

A dict representation of the JSON returned from the API.

Source code in src/tmdb_client_py/account.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
def guest_session_new(self, **kwargs):
    """
    This method will let you create a new guest session. Guest sessions
    are a type of session that will let a user rate movies and TV shows
    but not require them to have a TMDb user account. More
    information about user authentication can be found here
    (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

    Please note, you should only generate a single guest session per
    user (or device) as you will be able to attach the ratings to a
    TMDb user account in the future. There is also IP limits in place
    so you should always make sure it's the end user doing the guest
    session actions.

    If a guest session is not used for the first time within 24 hours,
    it will be automatically deleted.

    Args:

    Returns:
        A dict representation of the JSON returned from the API.
    """
    path = self._get_path("guest_session_new")

    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

session_delete(**kwargs)

If you would like to delete (or "logout") from a session, call this method with a valid session ID.

Args:

Returns:

Type Description

A dict representation of the JSON returned from the API.

Source code in src/tmdb_client_py/account.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
def session_delete(self, **kwargs):
    """
    If you would like to delete (or "logout") from a session, call this
    method with a valid session ID.

    Args:

    Returns:
        A dict representation of the JSON returned from the API.
    """
    path = self._get_path("session_delete")

    payload = {
        "session_id": kwargs.pop("session_id", None),
    }

    response = self._DELETE(path, kwargs, payload)
    self._set_attrs_to_values(response)
    return response

session_new(**kwargs)

You can use this method to create a fully valid session ID once a user has validated the request token. More information about how this works can be found here (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

Parameters:

Name Type Description Default
request_token

The token you generated for the user to approve. The token needs to be approved before being used here.

required

Returns:

Type Description

A dict representation of the JSON returned from the API.

Source code in src/tmdb_client_py/account.py
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
def session_new(self, **kwargs):
    """
    You can use this method to create a fully valid session ID once a user
    has validated the request token. More information about how this works
    can be found here
    (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

    Args:
        request_token: The token you generated for the user to approve.
                       The token needs to be approved before being
                       used here.

    Returns:
        A dict representation of the JSON returned from the API.
    """
    path = self._get_path("session_new")

    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

token_new(**kwargs)

Create a temporary request token that can be used to validate a TMDb user login. More details about how this works can be found here (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

Args:

Returns:

Type Description

A dict representation of the JSON returned from the API.

Source code in src/tmdb_client_py/account.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
def token_new(self, **kwargs):
    """
    Create a temporary request token that can be used to validate a TMDb
    user login. More details about how this works can be found here
    (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

    Args:

    Returns:
        A dict representation of the JSON returned from the API.
    """
    path = self._get_path("token_new")

    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

token_validate_with_login(**kwargs)

This method allows an application to validate a request token by entering a username and password.

Not all applications have access to a web view so this can be used as a substitute.

Please note, the preferred method of validating a request token is to have a user authenticate the request via the TMDb website. You can read about that method here (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

If you decide to use this method please use HTTPS.

Parameters:

Name Type Description Default
username

The user's username on TMDb.

required
password

The user's password on TMDb.

required
request_token

The token you generated for the user to approve.

required

Returns:

Type Description

A dict representation of the JSON returned from the API.

Source code in src/tmdb_client_py/account.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
def token_validate_with_login(self, **kwargs):
    """
    This method allows an application to validate a request token by entering
    a username and password.

    Not all applications have access to a web view so this can be used as a
    substitute.

    Please note, the preferred method of validating a request token is to
    have a user authenticate the request via the TMDb website. You can read
    about that method here
    (https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id).

    If you decide to use this method please use HTTPS.

    Args:
        username: The user's username on TMDb.
        password: The user's password on TMDb.
        request_token: The token you generated for the user to approve.

    Returns:
        A dict representation of the JSON returned from the API.
    """
    path = self._get_path("token_validate_with_login")

    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response