oauth2client.contrib.xsrfutil module

Helper methods for creating & verifying XSRF tokens.

oauth2client.contrib.xsrfutil.generate_token(*args, **kwargs)[source]

Generates a URL-safe token for the given user, action, time tuple.

Parameters:
  • key – secret key to use.
  • user_id – the user ID of the authenticated user.
  • action_id – a string identifier of the action they requested authorization for.
  • when – the time in seconds since the epoch at which the user was authorized for this action. If not set the current time is used.
Returns:

A string XSRF protection token.

oauth2client.contrib.xsrfutil.validate_token(*args, **kwargs)[source]

Validates that the given token authorizes the user for the action.

Tokens are invalid if the time of issue is too old or if the token does not match what generateToken outputs (i.e. the token was forged).

Parameters:
  • key – secret key to use.
  • token – a string of the token generated by generateToken.
  • user_id – the user ID of the authenticated user.
  • action_id – a string identifier of the action they requested authorization for.
Returns:

A boolean - True if the user is authorized for the action, False otherwise.