Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
A Python library for handling OAuth authentication, designed for use in third-party applications.
A Python library for handling OAuth authentication, designed for use in third-party applications. This package simplifies the process of obtaining authorization from OAuth provider, exchanging authorization codes for access tokens, refreshing access tokens, and retrieving user information.
To install the library, run:
pip install oauth-core-lib
Create a JSON Secrets File and add the following:
{
"google": {
"project_id": "your_project_id", // Optional buh good for identification
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"redirect_uris": "your_redirect_uri",
"status":"when status is set to test prompt is set to consent and this is good for testing"
}
}
Set Up Environment Variables Create a .env file in your project root directory with the following contents, the package will get the variables needed itself.
# Google credentials and url
GOOGLE_KEY=your_client_id
GOOGLE_SECRET=your_client_secret
GOOGLE_TOKEN_INFO=google_token_info_api
GOOGLE_API=google_api
from core.oauth import secrets
json_file = secrets.load_file(Path('your_json_file.json'))
# For google oauth
from core.oauth import google
oauth = google.GoogleOauth(json_file)
Generate the URL to redirect users to Google for authorization
auth_url = oauth.authorise()
Once the user is redirected back to your application, capture the query parameters (which include the authorization code) and exchange them for an access token (it takes in only dict)
query_params = {'code': 'authorization_code', 'state': 'your_state'} # query gotten from the redirect uri converted to dictionary
tokens = oauth.exchange_code(query_params)
access_token
: The token to authenticate API requests.
expires_in
: The remaining lifetime of the access token (in seconds).
refresh_token
: A token to obtain a new access token when the current one expires.
scope
: The scope of access granted by the user.
token_type
: The type of token issued (typically "Bearer").Check if the access token is still valid
token_info = oauth.check_access_token(tokens['access_token'])
aud
: The client ID to which the token was issued.
user_id
: The unique ID of the authenticated user.
scope
: The scope associated with the token.
expires_in
: The number of seconds remaining before the token expires.If the access token has expired, use the refresh token to get a new one note: refreash token does not come the second time
refreshed_tokens = oauth.refresh_token(tokens['refresh_token'])
exchange_code
, but without a new refreash_token
.Retrieve the authenticated user's information using the access token
user_info = oauth.do_auth(tokens['access_token'])
id
: The user's Google ID.
email
: The user's email address.
verified_email
: A boolean indicating whether the email address is verified.
name
: The user's full name.
given_name
: The user's first name.
family_name
: The user's last name.
picture
: The URL of the user's profile picture.Contributions are welcome! Please open an issue or submit a pull request for any bug fixes or enhancements.
This project is licensed under the MIT License.
FAQs
A Python library for handling OAuth authentication, designed for use in third-party applications.
We found that oauth-core-lib demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.