Skip to content

OAuth#

pyticktick.models.v1.parameters.oauth #

OAuth2 URL parameters for the V1 API.

This module contains the Pydantic models that generate the OAuth2 URLs for the V1 API authorization flow.

Classes:

Name Description
OAuthAuthorizeURLV1

OAuth2 authorize URL parameters for V1 API.

OAuthTokenURLV1

OAuth2 token URL parameters for V1 API.

OAuthAuthorizeURLV1 pydantic-model #

Bases: BaseModel

OAuth2 authorize URL parameters for V1 API.

Helper class to generate the OAuth2 authorize URL for the V1 API. This is the first step in the OAuth2 flow.

Example

from pyticktick.models.v1.parameters.oauth import OAuthAuthorizeURLV1

oauth_url = OAuthAuthorizeURLV1(client_id="your_client_id")
print(oauth_url.model_dump())
would print:
https://ticktick.com/oauth/authorize?client_id=your_client_id&scope=tasks%3Aread+tasks%3Awrite&state=None&response_type=code

Show JSON schema:
{
  "additionalProperties": false,
  "description": "OAuth2 authorize URL parameters for V1 API.\n\nHelper class to generate the OAuth2 authorize URL for the V1 API. This is the\n[first step](https://developer.ticktick.com/api#/openapi?id=first-step) in the\nOAuth2 flow.\n\n???+ example\n    ```python\n    from pyticktick.models.v1.parameters.oauth import OAuthAuthorizeURLV1\n\n    oauth_url = OAuthAuthorizeURLV1(client_id=\"your_client_id\")\n    print(oauth_url.model_dump())\n    ```\n    would print:\n    ```\n    https://ticktick.com/oauth/authorize?client_id=your_client_id&scope=tasks%3Aread+tasks%3Awrite&state=None&response_type=code\n    ```",
  "properties": {
    "client_id": {
      "description": "V1 API App unique client id. Taken from the [Manage Apps](https://developer.ticktick.com/manage) page.",
      "title": "Client Id",
      "type": "string"
    },
    "scope": {
      "const": "tasks:read tasks:write",
      "default": "tasks:read tasks:write",
      "description": "Spaces-separated permissions for the generated token. The currently available scopes are 'tasks:write' and 'tasks:read'. Default is 'tasks:read tasks:write'.",
      "title": "Scope",
      "type": "string"
    },
    "state": {
      "default": null,
      "description": "Passed to redirect url as is.",
      "title": "State"
    },
    "response_type": {
      "const": "code",
      "default": "code",
      "description": "Fixed value 'code'.",
      "title": "Response Type",
      "type": "string"
    },
    "base_url": {
      "default": "https://ticktick.com/oauth/authorize",
      "description": "OAuth2 authorize URL.",
      "format": "uri",
      "maxLength": 2083,
      "minLength": 1,
      "title": "Base Url",
      "type": "string"
    }
  },
  "required": [
    "client_id"
  ],
  "title": "OAuthAuthorizeURLV1",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

base_url pydantic-field #

base_url: HttpUrl = HttpUrl(
    "https://ticktick.com/oauth/authorize"
)

OAuth2 authorize URL.

client_id pydantic-field #

client_id: str

V1 API App unique client id. Taken from the Manage Apps page.

response_type pydantic-field #

response_type: Literal['code'] = 'code'

Fixed value 'code'.

scope pydantic-field #

scope: Literal["tasks:read tasks:write"] = (
    "tasks:read tasks:write"
)

Spaces-separated permissions for the generated token. The currently available scopes are 'tasks:write' and 'tasks:read'. Default is 'tasks:read tasks:write'.

state pydantic-field #

state: Any = None

Passed to redirect url as is.

ser_model #

ser_model() -> str

Serialize the model to a URL string.

Returns:

Name Type Description
str str

The URL string.

Source code in src/pyticktick/models/v1/parameters/oauth.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@model_serializer
def ser_model(self) -> str:
    """Serialize the model to a URL string.

    Returns:
        str: The URL string.
    """
    params = {
        "client_id": self.client_id,
        "scope": self.scope,
        "state": self.state,
        "response_type": self.response_type,
    }
    return f"{self.base_url}?{urlencode(params)}"

OAuthTokenURLV1 pydantic-model #

Bases: BaseModel

OAuth2 token URL parameters for V1 API.

Helper class to generate the OAuth2 token URL for the V1 API. This is the third step in the OAuth2 flow.

Example

from pyticktick.models.v1.parameters.oauth import OAuthTokenURLV1

oauth_url = OAuthTokenURLV1(
    client_id="your_client_id",
    client_secret="your_client_secret",
    code="your_code",
)
print(oauth_url.model_dump())
would print:
https://ticktick.com/oauth/token?client_id=your_client_id&client_secret=your_client_secret&code=your_code&grant_type=authorization_code&scope=tasks%3Aread+tasks%3Awrite&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2F

Show JSON schema:
{
  "additionalProperties": false,
  "description": "OAuth2 token URL parameters for V1 API.\n\nHelper class to generate the OAuth2 token URL for the V1 API. This is the\n[third step](https://developer.ticktick.com/api#/openapi?id=third-step) in the\nOAuth2 flow.\n\n???+ example\n    ```python\n    from pyticktick.models.v1.parameters.oauth import OAuthTokenURLV1\n\n    oauth_url = OAuthTokenURLV1(\n        client_id=\"your_client_id\",\n        client_secret=\"your_client_secret\",\n        code=\"your_code\",\n    )\n    print(oauth_url.model_dump())\n    ```\n    would print:\n    ```\n    https://ticktick.com/oauth/token?client_id=your_client_id&client_secret=your_client_secret&code=your_code&grant_type=authorization_code&scope=tasks%3Aread+tasks%3Awrite&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2F\n    ```",
  "properties": {
    "client_id": {
      "description": "V1 API App unique client id. Taken from the [Manage Apps](https://developer.ticktick.com/manage) page.",
      "title": "Client Id",
      "type": "string"
    },
    "client_secret": {
      "description": "V1 API App unique client secret. Taken from the [Manage Apps](https://developer.ticktick.com/manage) page.",
      "title": "Client Secret",
      "type": "string"
    },
    "code": {
      "description": "The code received from the OAuth2 authorize URL.",
      "title": "Code",
      "type": "string"
    },
    "oauth_redirect_url": {
      "default": "http://127.0.0.1:8080/",
      "description": "The redirect URL. Can be any URL, but should be one that does not collide with other applications.",
      "format": "uri",
      "maxLength": 2083,
      "minLength": 1,
      "title": "Oauth Redirect Url",
      "type": "string"
    },
    "scope": {
      "const": "tasks:read tasks:write",
      "default": "tasks:read tasks:write",
      "description": "Spaces-separated permissions for the generated token. The currently available scopes are 'tasks:write' and 'tasks:read'. Default is 'tasks:read tasks:write'.",
      "title": "Scope",
      "type": "string"
    },
    "grant_type": {
      "const": "authorization_code",
      "default": "authorization_code",
      "description": "Fixed value 'authorization_code'.",
      "title": "Grant Type",
      "type": "string"
    },
    "base_url": {
      "default": "https://ticktick.com/oauth/token",
      "description": "OAuth2 token URL.",
      "format": "uri",
      "maxLength": 2083,
      "minLength": 1,
      "title": "Base Url",
      "type": "string"
    }
  },
  "required": [
    "client_id",
    "client_secret",
    "code"
  ],
  "title": "OAuthTokenURLV1",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

base_url pydantic-field #

base_url: HttpUrl = HttpUrl(
    "https://ticktick.com/oauth/token"
)

OAuth2 token URL.

client_id pydantic-field #

client_id: str

V1 API App unique client id. Taken from the Manage Apps page.

client_secret pydantic-field #

client_secret: str

V1 API App unique client secret. Taken from the Manage Apps page.

code pydantic-field #

code: str

The code received from the OAuth2 authorize URL.

grant_type pydantic-field #

grant_type: Literal["authorization_code"] = (
    "authorization_code"
)

Fixed value 'authorization_code'.

oauth_redirect_url pydantic-field #

oauth_redirect_url: HttpUrl = HttpUrl(
    "http://127.0.0.1:8080/"
)

The redirect URL. Can be any URL, but should be one that does not collide with other applications.

scope pydantic-field #

scope: Literal["tasks:read tasks:write"] = (
    "tasks:read tasks:write"
)

Spaces-separated permissions for the generated token. The currently available scopes are 'tasks:write' and 'tasks:read'. Default is 'tasks:read tasks:write'.

ser_model #

ser_model() -> str

Serialize the model to a URL string.

Returns:

Name Type Description
str str

The OAuth URL string.

Source code in src/pyticktick/models/v1/parameters/oauth.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@model_serializer
def ser_model(self) -> str:
    """Serialize the model to a URL string.

    Returns:
        str: The OAuth URL string.
    """
    params = {
        "client_id": self.client_id,
        "client_secret": self.client_secret,
        "code": self.code,
        "grant_type": self.grant_type,
        "scope": self.scope,
        "redirect_uri": self.oauth_redirect_url,
    }
    return f"{self.base_url}?{urlencode(params)}"