dex-connector-linkedin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dex_connector_linkedin-0.1.0/.gitignore +16 -0
- dex_connector_linkedin-0.1.0/LICENSE +21 -0
- dex_connector_linkedin-0.1.0/PKG-INFO +17 -0
- dex_connector_linkedin-0.1.0/README.md +5 -0
- dex_connector_linkedin-0.1.0/examples/authenticated_profile/README.md +5 -0
- dex_connector_linkedin-0.1.0/examples/authenticated_profile/__init__.py +3 -0
- dex_connector_linkedin-0.1.0/examples/authenticated_profile/flow.py +73 -0
- dex_connector_linkedin-0.1.0/examples/authenticated_profile/integration_test.py +90 -0
- dex_connector_linkedin-0.1.0/examples/authenticated_profile/main.py +40 -0
- dex_connector_linkedin-0.1.0/pyproject.toml +38 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/__init__.py +27 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/__init__.py +2 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/config.py +28 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/connection.py +170 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/definitions.py +46 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/mock.py +128 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/models.py +35 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/refresh.py +9 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/_generated/steps.py +90 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/client.py +289 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/connection.py +8 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/dex-connector.json +64 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/linkedinmock/__init__.py +6 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/models.py +6 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/py.typed +0 -0
- dex_connector_linkedin-0.1.0/src/dex_connectors/linkedin/steps.py +5 -0
- dex_connector_linkedin-0.1.0/tests/refresh_agreement_cases.json +765 -0
- dex_connector_linkedin-0.1.0/tests/test_client.py +61 -0
- dex_connector_linkedin-0.1.0/tests/test_conformance.py +42 -0
- dex_connector_linkedin-0.1.0/tests/test_refresh_agreement.py +278 -0
- dex_connector_linkedin-0.1.0/uv.lock +866 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
|
+
/.bin/dexcli
|
|
8
|
+
/.bin/dex-server-zd
|
|
9
|
+
/sdkpython/.dexcli-data/
|
|
10
|
+
site/.catalog.yaml
|
|
11
|
+
coverage/
|
|
12
|
+
*.out
|
|
13
|
+
*.test
|
|
14
|
+
go.work
|
|
15
|
+
go.work.sum
|
|
16
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-linkedin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LinkedIn OpenID Connect UserInfo connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.7.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# LinkedIn Python connector
|
|
14
|
+
|
|
15
|
+
The `getAuthenticatedProfile` Query reads bounded OpenID Connect UserInfo claims and requires a verified email. Install `dex-connector-linkedin==0.1.0`. Project connections use generated OAuth refresh and credential wiring from Connector SDK 0.5.0. The runnable example is in `examples/authenticated_profile`.
|
|
16
|
+
|
|
17
|
+
Run `uv sync --locked` and `uv run pytest -q tests` from this directory. With `dexcli dev` running, set `DEX_FLOW_SERVICE_ADDRESS` and run `uv run pytest -q examples/authenticated_profile/integration_test.py`. The example uses the generated OAuth project connection and a static connection name. Live LinkedIn authorization and UserInfo behavior have not been verified.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# LinkedIn Python connector
|
|
2
|
+
|
|
3
|
+
The `getAuthenticatedProfile` Query reads bounded OpenID Connect UserInfo claims and requires a verified email. Install `dex-connector-linkedin==0.1.0`. Project connections use generated OAuth refresh and credential wiring from Connector SDK 0.5.0. The runnable example is in `examples/authenticated_profile`.
|
|
4
|
+
|
|
5
|
+
Run `uv sync --locked` and `uv run pytest -q tests` from this directory. With `dexcli dev` running, set `DEX_FLOW_SERVICE_ADDRESS` and run `uv run pytest -q examples/authenticated_profile/integration_test.py`. The example uses the generated OAuth project connection and a static connection name. Live LinkedIn authorization and UserInfo behavior have not been verified.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# LinkedIn authenticated profile Python example
|
|
2
|
+
|
|
3
|
+
Create a Dex Web connection named `linkedin-signup`. Configure a LinkedIn developer application at https://www.linkedin.com/developers/apps with the Sign in with LinkedIn using OpenID Connect product, its redirect URI, and `openid profile email` scopes. Set `DEX_FLOW_SERVICE_ADDRESS` to a running `dexcli dev` Flow Service and run `python -m examples.authenticated_profile.main` from `connectors/linkedin/python`. Start `LinkedInAuthenticatedProfilePython` with `{}`. The Flow stores the verified profile and completes. Optional failure branches remain unwired and fail the Flow.
|
|
4
|
+
|
|
5
|
+
The integration test runs a real Dex Worker and Client against `dexcli dev` with a local HTTP provider stand-in. Live LinkedIn authorization and UserInfo behavior remain unverified.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable LinkedIn authenticated profile Flow."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
import dex
|
|
8
|
+
from dex_connectors.sdk import QueryResult
|
|
9
|
+
|
|
10
|
+
from dex_connectors.linkedin import (
|
|
11
|
+
AuthenticatedProfile,
|
|
12
|
+
Connection,
|
|
13
|
+
GetAuthenticatedProfileInput,
|
|
14
|
+
new_get_authenticated_profile_step,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTION_NAME = "linkedin-signup"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class ProfileInput:
|
|
22
|
+
"""No provider fields are needed for the authenticated member."""
|
|
23
|
+
|
|
24
|
+
def to_operation_input(self) -> GetAuthenticatedProfileInput:
|
|
25
|
+
"""Build the empty UserInfo request."""
|
|
26
|
+
return GetAuthenticatedProfileInput()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
profile_attribute = dex.Attribute("linkedin-authenticated-profile", AuthenticatedProfile)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# dex:group group-id:linkedin-profile group-label:"LinkedIn Profile"
|
|
33
|
+
# dex:explanation text:"Persist the verified profile and complete the signup Flow."
|
|
34
|
+
class CompleteProfile(dex.Step[QueryResult[AuthenticatedProfile]]):
|
|
35
|
+
"""Save the verified UserInfo claims and complete the Flow."""
|
|
36
|
+
|
|
37
|
+
def execute(self, context: dex.Context, input: QueryResult[AuthenticatedProfile]) -> dex.StepDecision:
|
|
38
|
+
"""Persist the public profile without credentials."""
|
|
39
|
+
profile_attribute.set(context, input.value)
|
|
40
|
+
return dex.graceful_complete(input.value)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ProfileFlow(dex.Flow[ProfileInput]):
|
|
44
|
+
"""Query LinkedIn through a static named connection."""
|
|
45
|
+
|
|
46
|
+
def __init__(self, connection: Connection) -> None:
|
|
47
|
+
"""Bind the UserInfo Query before Worker registration."""
|
|
48
|
+
self.complete = CompleteProfile()
|
|
49
|
+
self.get_profile = new_get_authenticated_profile_step(
|
|
50
|
+
step_type="GetAuthenticatedProfile",
|
|
51
|
+
step_input_type=ProfileInput,
|
|
52
|
+
annotations={
|
|
53
|
+
"groupId": "linkedin-profile",
|
|
54
|
+
"groupLabel": "LinkedIn Profile",
|
|
55
|
+
"explanation": "Load the verified LinkedIn UserInfo profile.",
|
|
56
|
+
},
|
|
57
|
+
connection=connection,
|
|
58
|
+
connection_name=CONNECTION_NAME,
|
|
59
|
+
map_to_operation_input=ProfileInput.to_operation_input,
|
|
60
|
+
profile_loaded=self.complete,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def get_flow_type(self) -> str:
|
|
64
|
+
"""Keep the example Flow identity stable."""
|
|
65
|
+
return "LinkedInAuthenticatedProfilePython"
|
|
66
|
+
|
|
67
|
+
def get_steps(self) -> dex.StepList[ProfileInput]:
|
|
68
|
+
"""Query and store the authenticated profile."""
|
|
69
|
+
return dex.StepList.start_step(self.get_profile).other_steps(self.complete)
|
|
70
|
+
|
|
71
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
72
|
+
"""Register the result Attribute consumed by the Flow."""
|
|
73
|
+
return dex.PersistenceSchema.of(profile_attribute)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Exercise LinkedIn UserInfo through a real Dex Worker and Client."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from datetime import timedelta
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from uuid import uuid4
|
|
11
|
+
|
|
12
|
+
import dex
|
|
13
|
+
import pytest
|
|
14
|
+
from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
|
|
15
|
+
|
|
16
|
+
from dex_connectors.linkedin import AuthenticatedProfile, Client, Config, Credentials, new_connection
|
|
17
|
+
|
|
18
|
+
from .flow import CONNECTION_NAME, ProfileFlow, ProfileInput
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.mark.asyncio
|
|
22
|
+
async def test_profile_query_and_unwired_failure_in_real_dex() -> None:
|
|
23
|
+
"""Verify successful routing and optional failure with a local provider."""
|
|
24
|
+
server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
25
|
+
requests: list[bytes] = []
|
|
26
|
+
|
|
27
|
+
async def answer(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
|
|
28
|
+
request = await reader.readuntil(b"\r\n\r\n")
|
|
29
|
+
requests.append(request)
|
|
30
|
+
if len(requests) == 1:
|
|
31
|
+
status, body = 200, b'{"sub":"member","email":"member@example.com","email_verified":true}'
|
|
32
|
+
else:
|
|
33
|
+
status, body = 404, b"{}"
|
|
34
|
+
header = (
|
|
35
|
+
f"HTTP/1.1 {status} {'OK' if status == 200 else 'Not Found'}\r\n"
|
|
36
|
+
f"Content-Type: application/json\r\nContent-Length: {len(body)}\r\n"
|
|
37
|
+
"Connection: close\r\n\r\n"
|
|
38
|
+
)
|
|
39
|
+
writer.write(header.encode() + body)
|
|
40
|
+
await writer.drain()
|
|
41
|
+
writer.close()
|
|
42
|
+
await writer.wait_closed()
|
|
43
|
+
|
|
44
|
+
provider = await asyncio.start_server(answer, "127.0.0.1", 0)
|
|
45
|
+
provider_port = provider.sockets[0].getsockname()[1]
|
|
46
|
+
reference = ConnectionRef("linkedin", CONNECTION_NAME)
|
|
47
|
+
credentials = Credentials("", SecretString(""), SecretString("inert-test-token"), SecretString(""))
|
|
48
|
+
client = Client(
|
|
49
|
+
Config(user_info_url=f"http://127.0.0.1:{provider_port}/v2/userinfo"),
|
|
50
|
+
StaticCredentialProvider({reference: credentials}),
|
|
51
|
+
)
|
|
52
|
+
connection = new_connection(client, reference)
|
|
53
|
+
flow = ProfileFlow(connection)
|
|
54
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
55
|
+
try:
|
|
56
|
+
with tempfile.TemporaryDirectory(prefix="linkedin-python-dex-blobs-") as cache_directory:
|
|
57
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(Path(cache_directory) / "blobs"), 1 << 24))
|
|
58
|
+
try:
|
|
59
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
|
|
60
|
+
worker_task = asyncio.create_task(worker.start())
|
|
61
|
+
try:
|
|
62
|
+
await worker.wait_pull_registered(timeout=15)
|
|
63
|
+
async with dex.AsyncClient(
|
|
64
|
+
registry, cache, dex.ClientOptions(server_address=server_address)
|
|
65
|
+
) as dex_client:
|
|
66
|
+
completed_id = f"linkedin-python-{uuid4().hex}"
|
|
67
|
+
await dex_client.start_flow(flow, completed_id, ProfileInput())
|
|
68
|
+
completed = await asyncio.wait_for(
|
|
69
|
+
dex_client.wait_for_flow(completed_id, timedelta(seconds=20)), 30
|
|
70
|
+
)
|
|
71
|
+
assert completed.status == dex.FlowStatus.COMPLETED, completed.error_message
|
|
72
|
+
profile = completed.single_output(AuthenticatedProfile)
|
|
73
|
+
assert profile.subject == "member" and profile.verified_email == "member@example.com"
|
|
74
|
+
missing_id = f"linkedin-python-{uuid4().hex}"
|
|
75
|
+
await dex_client.start_flow(flow, missing_id, ProfileInput())
|
|
76
|
+
missing = await asyncio.wait_for(
|
|
77
|
+
dex_client.wait_for_flow(missing_id, timedelta(seconds=20)), 30
|
|
78
|
+
)
|
|
79
|
+
assert missing.status == dex.FlowStatus.FAILED
|
|
80
|
+
assert "notFound" in (missing.error_message or "")
|
|
81
|
+
assert len(requests) == 2
|
|
82
|
+
finally:
|
|
83
|
+
await worker.stop()
|
|
84
|
+
await worker_task
|
|
85
|
+
finally:
|
|
86
|
+
cache.close()
|
|
87
|
+
finally:
|
|
88
|
+
await client.aclose()
|
|
89
|
+
provider.close()
|
|
90
|
+
await provider.wait_closed()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Run the LinkedIn profile Worker with a Dex project connection."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.linkedin import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, ProfileFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run() -> None:
|
|
19
|
+
"""Load project OAuth configuration and serve the profile Flow."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
22
|
+
cache = dex.open_blob_cache(
|
|
23
|
+
dex.BlobCacheConfig(str(Path(tempfile.gettempdir()) / "dex-linkedin-python-blobs"), 1 << 30)
|
|
24
|
+
)
|
|
25
|
+
try:
|
|
26
|
+
registry = dex.Registry([ProfileFlow(connection)], allow_async_handlers=True)
|
|
27
|
+
async with dex.AsyncWorker(
|
|
28
|
+
registry,
|
|
29
|
+
cache,
|
|
30
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
31
|
+
) as worker:
|
|
32
|
+
await worker.start()
|
|
33
|
+
finally:
|
|
34
|
+
cache.close()
|
|
35
|
+
await connection.aclose()
|
|
36
|
+
await project.close()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
asyncio.run(run())
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-linkedin"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "LinkedIn OpenID Connect UserInfo connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["dex-connectors-sdk==0.7.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
14
|
+
|
|
15
|
+
[dependency-groups]
|
|
16
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7"]
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["src/dex_connectors"]
|
|
20
|
+
|
|
21
|
+
[tool.pytest.ini_options]
|
|
22
|
+
testpaths = ["tests"]
|
|
23
|
+
pythonpath = [".", "src"]
|
|
24
|
+
asyncio_mode = "auto"
|
|
25
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
python_version = "3.11"
|
|
29
|
+
strict = true
|
|
30
|
+
mypy_path = "src"
|
|
31
|
+
explicit_package_bases = true
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
target-version = "py311"
|
|
35
|
+
line-length = 110
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""LinkedIn OpenID Connect connector for Dex Python applications."""
|
|
4
|
+
|
|
5
|
+
from .client import Client as Client
|
|
6
|
+
from .client import Config as Config
|
|
7
|
+
from .client import Credentials as Credentials
|
|
8
|
+
from .connection import Connection as Connection
|
|
9
|
+
from .connection import new_connection as new_connection
|
|
10
|
+
from .connection import new_connection_with_operations as new_connection_with_operations
|
|
11
|
+
from .connection import new_project_connection as new_project_connection
|
|
12
|
+
from .models import AuthenticatedProfile as AuthenticatedProfile
|
|
13
|
+
from .models import GetAuthenticatedProfileInput as GetAuthenticatedProfileInput
|
|
14
|
+
from .steps import new_get_authenticated_profile_step as new_get_authenticated_profile_step
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"AuthenticatedProfile",
|
|
18
|
+
"Client",
|
|
19
|
+
"Config",
|
|
20
|
+
"Connection",
|
|
21
|
+
"Credentials",
|
|
22
|
+
"GetAuthenticatedProfileInput",
|
|
23
|
+
"new_connection",
|
|
24
|
+
"new_connection_with_operations",
|
|
25
|
+
"new_get_authenticated_profile_step",
|
|
26
|
+
"new_project_connection",
|
|
27
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
user_info_url: str = "https://api.linkedin.com/v2/userinfo"
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 1048576
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.linkedin.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
oauth_client_id: str
|
|
24
|
+
oauth_client_secret: SecretString
|
|
25
|
+
access_token: SecretString
|
|
26
|
+
refresh_token: SecretString
|
|
27
|
+
|
|
28
|
+
setattr(Credentials, '__module__', 'dex_connectors.linkedin.client')
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Query, Call, SecretString, CredentialRefreshDriver
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
from dex_connectors.sdk.projectconfig.provider import RefreshingCredentialProvider
|
|
11
|
+
from dex_connectors.sdk.oauthtoken import ManifestCredentialRefreshDriver
|
|
12
|
+
|
|
13
|
+
from ..client import Client, Config, Credentials
|
|
14
|
+
from .definitions import CONNECTOR_ID, GET_AUTHENTICATED_PROFILE_DEFINITION
|
|
15
|
+
from .refresh import AUTHORIZATION, CREDENTIAL_FIELDS
|
|
16
|
+
from ..models import AuthenticatedProfile, GetAuthenticatedProfileInput
|
|
17
|
+
|
|
18
|
+
class Connection:
|
|
19
|
+
|
|
20
|
+
__slots__ = ('_get_authenticated_profile', '_client', 'reference')
|
|
21
|
+
|
|
22
|
+
def __init__(self,
|
|
23
|
+
reference: ConnectionRef,
|
|
24
|
+
get_authenticated_profile: Query[GetAuthenticatedProfileInput, AuthenticatedProfile],
|
|
25
|
+
client: Client | None = None,
|
|
26
|
+
) -> None:
|
|
27
|
+
reference.validate()
|
|
28
|
+
if reference.provider != CONNECTOR_ID or get_authenticated_profile is None:
|
|
29
|
+
raise ValueError("LinkedIn connection provider and operations are required")
|
|
30
|
+
if get_authenticated_profile.definition().operation != GET_AUTHENTICATED_PROFILE_DEFINITION.operation:
|
|
31
|
+
raise ValueError("LinkedIn connection operation identity differs")
|
|
32
|
+
self.reference = reference
|
|
33
|
+
self._get_authenticated_profile = get_authenticated_profile
|
|
34
|
+
self._client = client
|
|
35
|
+
|
|
36
|
+
def get_authenticated_profile(self) -> Query[GetAuthenticatedProfileInput, AuthenticatedProfile]:
|
|
37
|
+
return self._get_authenticated_profile
|
|
38
|
+
|
|
39
|
+
async def aclose(self) -> None:
|
|
40
|
+
if self._client is not None:
|
|
41
|
+
await self._client.aclose()
|
|
42
|
+
|
|
43
|
+
def __repr__(self) -> str:
|
|
44
|
+
return "linkedin.Connection([REDACTED])"
|
|
45
|
+
|
|
46
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
47
|
+
raise TypeError("LinkedIn connections cannot be serialized")
|
|
48
|
+
|
|
49
|
+
setattr(Connection, '__module__', 'dex_connectors.linkedin.connection')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
53
|
+
if client is None:
|
|
54
|
+
raise ValueError("LinkedIn client is required")
|
|
55
|
+
return Connection(reference, client.get_authenticated_profile(), client)
|
|
56
|
+
|
|
57
|
+
setattr(new_connection, '__module__', 'dex_connectors.linkedin.connection')
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def new_connection_with_operations(
|
|
61
|
+
get_authenticated_profile: Query[GetAuthenticatedProfileInput, AuthenticatedProfile],
|
|
62
|
+
reference: ConnectionRef,
|
|
63
|
+
) -> Connection:
|
|
64
|
+
return Connection(reference, get_authenticated_profile)
|
|
65
|
+
|
|
66
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.linkedin.connection')
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def decode_credentials(material: dict[str, Any], *, shared: bool = False) -> Credentials:
|
|
70
|
+
if not isinstance(material, dict):
|
|
71
|
+
raise ValueError("LinkedIn stored credential does not match the connector credential fields")
|
|
72
|
+
if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token')):
|
|
73
|
+
raise ValueError("LinkedIn stored credential does not match the connector credential fields")
|
|
74
|
+
oauth_client_id = material.get("oauth_client_id")
|
|
75
|
+
if oauth_client_id is not None and not (isinstance(oauth_client_id, str)):
|
|
76
|
+
raise ValueError("LinkedIn credential oauth_client_id has an invalid type")
|
|
77
|
+
oauth_client_secret = material.get("oauth_client_secret")
|
|
78
|
+
if oauth_client_secret is not None and not (isinstance(oauth_client_secret, str)):
|
|
79
|
+
raise ValueError("LinkedIn credential oauth_client_secret has an invalid type")
|
|
80
|
+
access_token = material.get("access_token")
|
|
81
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
82
|
+
raise ValueError("LinkedIn credential access_token has an invalid type")
|
|
83
|
+
refresh_token = material.get("refresh_token")
|
|
84
|
+
if refresh_token is not None and not (isinstance(refresh_token, str)):
|
|
85
|
+
raise ValueError("LinkedIn credential refresh_token has an invalid type")
|
|
86
|
+
if not access_token:
|
|
87
|
+
raise ValueError("LinkedIn credential access_token is required")
|
|
88
|
+
return Credentials((oauth_client_id or ''), SecretString(oauth_client_secret or ''), SecretString(access_token), SecretString(refresh_token or ''))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
|
|
92
|
+
return decode_credentials(material, shared=True)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def encode_credentials(credentials: Credentials) -> dict[str, Any]:
|
|
96
|
+
material: dict[str, Any] = {}
|
|
97
|
+
if credentials.oauth_client_id:
|
|
98
|
+
material["oauth_client_id"] = credentials.oauth_client_id
|
|
99
|
+
if credentials.oauth_client_secret.reveal():
|
|
100
|
+
material["oauth_client_secret"] = credentials.oauth_client_secret.reveal()
|
|
101
|
+
if credentials.access_token.reveal():
|
|
102
|
+
material["access_token"] = credentials.access_token.reveal()
|
|
103
|
+
if credentials.refresh_token.reveal():
|
|
104
|
+
material["refresh_token"] = credentials.refresh_token.reveal()
|
|
105
|
+
decode_credentials(material)
|
|
106
|
+
return material
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class _ProjectCredentialSource:
|
|
110
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey, http_client: httpx.AsyncClient, settings: dict[str, Any]) -> None:
|
|
111
|
+
self.provider = RefreshingCredentialProvider(
|
|
112
|
+
project.connections, key, decode_credentials, encode_credentials, decode_shared_credentials
|
|
113
|
+
)
|
|
114
|
+
self.driver = ManifestCredentialRefreshDriver[Credentials]("LinkedIn", AUTHORIZATION, CREDENTIAL_FIELDS, http_client, settings=settings)
|
|
115
|
+
|
|
116
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
117
|
+
return await self.provider.resolve_with_refresh(call, self.driver)
|
|
118
|
+
|
|
119
|
+
async def resolve_with_refresh(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
120
|
+
return await self.provider.resolve_with_refresh(call, driver or self.driver)
|
|
121
|
+
|
|
122
|
+
async def resolve_after_rejection(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
123
|
+
return await self.provider.resolve_after_rejection(call, driver or self.driver)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def new_project_connection(
|
|
127
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
128
|
+
) -> Connection:
|
|
129
|
+
if project is None:
|
|
130
|
+
raise ValueError("LinkedIn connection requires loaded project configuration")
|
|
131
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
132
|
+
reference.validate()
|
|
133
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
134
|
+
matching = [
|
|
135
|
+
entry
|
|
136
|
+
for entry in project.configuration.connections
|
|
137
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
138
|
+
]
|
|
139
|
+
if len(matching) != 1:
|
|
140
|
+
raise ValueError("LinkedIn project connection is missing or duplicated")
|
|
141
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
142
|
+
raise ValueError("LinkedIn project connection provider differs")
|
|
143
|
+
config = _decode_config(matching[0].configuration)
|
|
144
|
+
http_client = http_client or httpx.AsyncClient()
|
|
145
|
+
client = Client(config, _ProjectCredentialSource(project, key, http_client, matching[0].configuration), http_client)
|
|
146
|
+
return new_connection(client, reference)
|
|
147
|
+
|
|
148
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.linkedin.connection')
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
152
|
+
if set(value) - {"userInfoUrl", "timeout", "maxResponseBytes"}:
|
|
153
|
+
raise ValueError("LinkedIn configuration has unknown fields")
|
|
154
|
+
config_arguments: dict[str, Any] = {}
|
|
155
|
+
if "userInfoUrl" in value and value["userInfoUrl"] != '':
|
|
156
|
+
user_info_url = value["userInfoUrl"]
|
|
157
|
+
if not (isinstance(user_info_url, str)):
|
|
158
|
+
raise ValueError("LinkedIn configuration userInfoUrl has an invalid type")
|
|
159
|
+
config_arguments['user_info_url'] = user_info_url
|
|
160
|
+
if "timeout" in value and value["timeout"] != '':
|
|
161
|
+
timeout = value["timeout"]
|
|
162
|
+
if not (type(timeout) is int):
|
|
163
|
+
raise ValueError("LinkedIn configuration timeout has an invalid type")
|
|
164
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
165
|
+
if "maxResponseBytes" in value and value["maxResponseBytes"] != '':
|
|
166
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
167
|
+
if not (type(max_response_bytes) is int):
|
|
168
|
+
raise ValueError("LinkedIn configuration maxResponseBytes has an invalid type")
|
|
169
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
170
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "linkedin"
|
|
18
|
+
PROVIDER = "linkedin"
|
|
19
|
+
GET_AUTHENTICATED_PROFILE_OPERATION_ID = "getAuthenticatedProfile"
|
|
20
|
+
AUTHORIZATION_REVOKED = "authorizationRevoked"
|
|
21
|
+
DEFECT = "defect"
|
|
22
|
+
INSUFFICIENT_SCOPE = "insufficientScope"
|
|
23
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
24
|
+
NOT_FOUND = "notFound"
|
|
25
|
+
PROFILE_LOADED = "profileLoaded"
|
|
26
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
27
|
+
VERIFIED_EMAIL_REQUIRED = "verifiedEmailRequired"
|
|
28
|
+
|
|
29
|
+
GET_AUTHENTICATED_PROFILE_DEFINITION = QueryDefinition(
|
|
30
|
+
OperationRef(CONNECTOR_ID, GET_AUTHENTICATED_PROFILE_OPERATION_ID),
|
|
31
|
+
(
|
|
32
|
+
BranchDefinition(PROFILE_LOADED, "The authenticated profile and verified email were loaded.", False),
|
|
33
|
+
BranchDefinition(VERIFIED_EMAIL_REQUIRED, "A verified email was not available.", True),
|
|
34
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OpenID Connect grant lacks required authorization.", True),
|
|
35
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OpenID Connect grant is invalid or revoked.", True),
|
|
36
|
+
BranchDefinition(NOT_FOUND, "The authenticated member was not found.", True),
|
|
37
|
+
BranchDefinition(PROVIDER_REJECTED, "LinkedIn conclusively rejected the profile query.", True),
|
|
38
|
+
BranchDefinition(INVALID_RESPONSE, "LinkedIn returned an invalid or oversized profile response.", True),
|
|
39
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
40
|
+
),
|
|
41
|
+
StepDefaults(
|
|
42
|
+
timedelta(seconds=30),
|
|
43
|
+
2,
|
|
44
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
45
|
+
),
|
|
46
|
+
)
|