-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: 📚 added AuthClient docs, 2-legged oauth example (#7)
- Loading branch information
Showing
6 changed files
with
230 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Example calls to fetch a 2-legged access token and introspect the token. A 2-legged access token | ||
obtained using the Client Credentials Flow, allows your application to access APIs that are not member | ||
specific. | ||
Note: By default, developer applications do NOT have the Client Credentials Flow (2-legged) enabled. This | ||
example will only work if your application has had this flow enabled. | ||
""" | ||
|
||
import os,sys | ||
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | ||
|
||
from dotenv import load_dotenv,find_dotenv | ||
load_dotenv(find_dotenv()) | ||
|
||
from linkedin_api.clients.auth.client import AuthClient | ||
|
||
CLIENT_ID = os.getenv("CLIENT_ID") | ||
CLIENT_SECRET = os.getenv("CLIENT_SECRET") | ||
|
||
auth_client = AuthClient( | ||
client_id=CLIENT_ID, | ||
client_secret=CLIENT_SECRET | ||
) | ||
|
||
token_response = auth_client.get_two_legged_access_token() | ||
access_token = token_response.access_token | ||
print(f"Status code: {token_response.status_code}") | ||
print(f"Access token: {access_token}\n") | ||
|
||
if access_token: | ||
introspection_response = auth_client.introspect_access_token(access_token) | ||
print("Token introspection details:") | ||
print(f"Auth type: {introspection_response.auth_type}") | ||
print(f"Expires at: {introspection_response.expires_at}") |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,111 @@ | ||
from typing import Dict, Any | ||
|
||
from linkedin_api.clients.common.response import BaseResponse | ||
|
||
class BaseAuthResponse(BaseResponse): | ||
pass | ||
|
||
class AccessToken3LResponse(BaseAuthResponse): | ||
def __init__(self, status_code, url, headers, response, access_token, expires_in, refresh_token, refresh_token_expires_in, scope): | ||
super().__init__(status_code=status_code, url=url, headers=headers, response=response) | ||
self.access_token = access_token | ||
self.expires_in = expires_in | ||
self.refresh_token = refresh_token | ||
self.refresh_token_expires_in = refresh_token_expires_in | ||
self.scope = scope | ||
super().__init__(status_code=status_code, url=url, headers=headers, response=response) | ||
self.access_token = access_token | ||
""" | ||
The 3-legged access token. | ||
""" | ||
|
||
self.expires_in = expires_in | ||
""" | ||
The TTL for the access token, in seconds. | ||
""" | ||
|
||
self.refresh_token = refresh_token | ||
""" | ||
The refresh token value. Only available if refresh tokens are enabled. | ||
""" | ||
|
||
self.refresh_token_expires_in = refresh_token_expires_in | ||
""" | ||
The TTL for the refresh token, in seconds. Only available if refresh tokens are enabled. | ||
""" | ||
|
||
self.scope = scope | ||
""" | ||
A comma-separated list of scopes authorized by the member (e.g. "r_liteprofile,r_ads"). | ||
""" | ||
|
||
class AccessToken2LResponse(BaseAuthResponse): | ||
def __init__(self, status_code, url, headers, response, access_token, expires_in): | ||
super().__init__(status_code=status_code, url=url, headers=headers, response=response) | ||
self.access_token = access_token | ||
self.expires_in = expires_in | ||
super().__init__(status_code=status_code, url=url, headers=headers, response=response) | ||
self.access_token = access_token | ||
""" | ||
The two-legged access token. | ||
""" | ||
|
||
self.expires_in = expires_in | ||
""" | ||
The TTL of the access token, in seconds. | ||
""" | ||
|
||
class IntrospectTokenResponse(BaseAuthResponse): | ||
def __init__(self, status_code, url, headers, response, active, auth_type, authorized_at, client_id, created_at, expires_at, scope, status): | ||
super().__init__(status_code=status_code, url=url, headers=headers, response=response) | ||
self.active = active | ||
""" | ||
Boolean flag whether the token is a valid, active token. | ||
""" | ||
|
||
self.auth_type = auth_type | ||
""" | ||
The auth type of the token ("2L", "3L" or "Enterprise_User") | ||
""" | ||
|
||
self.authorized_at = authorized_at | ||
""" | ||
Epoch time in seconds, indicating when the token was authorized. | ||
""" | ||
|
||
self.client_id = client_id | ||
""" | ||
Developer application client ID. | ||
""" | ||
|
||
self.created_at = created_at | ||
""" | ||
Epoch time in seconds, indicating when this token was originally issued. | ||
""" | ||
|
||
self.expires_at = expires_at | ||
""" | ||
Epoch time in seconds, indicating when this token will expire. | ||
""" | ||
|
||
self.scope = scope | ||
""" | ||
A string containing a comma-separated list of scopes associated with this token. This is only returned for 3-legged member tokens. | ||
""" | ||
|
||
self.status = status | ||
""" | ||
The token status ("revoked", "expired", or "active") | ||
""" | ||
|
||
class RefreshTokenExchangeResponse(BaseAuthResponse): | ||
def __init__(self, status_code, url, headers, response, access_token, expires_in, refresh_token, refresh_token_expires_in): | ||
super().__init__(status_code=status_code, url=url, headers=headers, response=response) | ||
self.access_token = access_token | ||
""" | ||
The 3-legged access token. | ||
""" | ||
|
||
self.expires_in = expires_in | ||
""" | ||
The TTL for the access token, in seconds. | ||
""" | ||
|
||
self.refresh_token = refresh_token | ||
""" | ||
The refresh token value. | ||
""" | ||
|
||
self.refresh_token_expires_in = refresh_token_expires_in | ||
""" | ||
The TTL for the refresh token, in seconds. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters