René's URL Explorer Experiment


Title: Feature/oauth client credentials 2026 by lvalics · Pull Request #787 · Shopify/shopify_python_api · GitHub

Open Graph Title: Feature/oauth client credentials 2026 by lvalics · Pull Request #787 · Shopify/shopify_python_api

X Title: Feature/oauth client credentials 2026 by lvalics · Pull Request #787 · Shopify/shopify_python_api

Description: Complete OAuth 2.0 Client Credentials Grant Support for Shopify API 2026-01+ Overview This PR adds comprehensive OAuth 2.0 Client Credentials Grant support required for Shopify API version 2026-01 and later, including automatic version detection, token expiration tracking, automatic refresh, and scope filtering for multi-API apps. Background Shopify API 2026-01+ Changes: Apps created in the new Shopify Dev Dashboard use OAuth 2.0 Client Credentials Grant (RFC 6749 Section 4.4) Tokens expire after 24 hours (86,399 seconds) Multiple API types can be configured: Admin API, Customer Account API, Storefront API /admin/oauth/access_token endpoint only supports Admin API scopes Previous Limitations: No built-in support for client credentials flow No automatic token refresh mechanism No way to filter scopes when apps have multiple API types configured Risk of authentication failures during long-running operations Features 1. OAuth 2.0 Client Credentials Grant Support New Methods: Session.request_token_client_credentials() - Exchange client credentials for access token Session.request_access_token() - Smart method that automatically selects correct OAuth flow based on API version New Exception: OAuthException - OAuth-specific errors with detailed error information Automatic Version Detection: API versions >= 2026-01 automatically use client credentials flow Older versions continue using authorization code grant Legacy request_token() raises ValidationException for API versions >= 2026-01 Example: import shopify shopify.Session.setup(api_key="client_id", secret="client_secret") session = shopify.Session("mystore.myshopify.com", "2026-01") # Automatically uses correct flow based on API version response = session.request_access_token() # Returns: {'access_token': 'shpca_...', 'scope': '...', 'expires_in': 86399} 2. Token Expiration Tracking and Automatic Refresh New Methods: Session.is_token_expired(buffer_seconds=300) - Check if token is expired or expiring soon Session.refresh_token_if_needed(buffer_seconds=300) - Automatically refresh token if expired or expiring soon Session.refresh_token() - Manually force token refresh regardless of expiration status Token Lifecycle Management: Session tracks token_obtained_at and token_expires_at timestamps Default 5-minute buffer before expiration ensures proactive refresh Prevents authentication failures during long-running operations Example: # Set up session with existing token session = shopify.Session("mystore.myshopify.com", "2026-01", "existing_token") session.token_obtained_at = datetime.now() - timedelta(hours=23) session.token_expires_at = datetime.now() + timedelta(hours=1) # Automatically refresh if needed (with 5-minute buffer) result = session.refresh_token_if_needed() if result: print(f"Token refreshed! New token: {result['access_token']}") else: print("Token still valid, no refresh needed") # Or force refresh manually result = session.refresh_token() print(f"Token refreshed! Expires in {result['expires_in']} seconds") 3. OAuth Scope Filtering Support Problem Solved: When apps have multiple API types configured (Admin API + Customer Account API + Storefront API), requesting tokens through /admin/oauth/access_token fails because that endpoint only supports Admin API scopes. Solution: All OAuth methods now accept optional scope parameter to request specific scopes. New Functionality: request_token_client_credentials(scope=None) request_access_token(scope=None) refresh_token_if_needed(scope=None) refresh_token(scope=None) Scope Normalization: Comma-separated scopes automatically converted to space-separated for OAuth 2.0 spec compliance Example: "read_products,write_products" → "read_products write_products" Example: # App has Admin API + Customer Account API scopes configured shopify.Session.setup(api_key="client_id", secret="client_secret") session = shopify.Session("mystore.myshopify.com", "2026-01") # Request ONLY Admin API scopes (even though app has Customer Account API configured) response = session.request_access_token( scope="read_products write_products read_orders write_orders" ) # Success! Token granted with Admin API scopes only # Auto-refresh with specific scopes result = session.refresh_token_if_needed( scope="read_products write_products read_orders write_orders" ) Use Case - Mixed API Types: Shopify app configuration: Admin API: - read_products, write_products - read_orders, write_orders Customer Account API: - customer_read_metaobjects ← Would cause error without scope filtering Storefront API: - unauthenticated_read_metaobjects Before (fails): # Tries to request ALL scopes through /admin/oauth/access_token response = session.request_access_token() # Error: 'customer_read_metaobjects' is not a valid access scope After (works): # Request only Admin API scopes response = session.request_access_token( scope="read_products write_products read_orders write_orders" ) # Success! ✓ Complete Usage Example import shopify from datetime import datetime, timedelta # Setup credentials shopify.Session.setup(api_key="client_id", secret="client_secret") # Create session for 2026-01 API session = shopify.Session("mystore.myshopify.com", "2026-01") # 1. Get initial token with Admin API scopes only response = session.request_access_token( scope="read_products write_products read_orders write_orders" ) print(f"Token: {response['access_token']}") print(f"Expires in: {response['expires_in']} seconds") print(f"Scopes: {response['scope']}") # Session now has token and expiration tracking print(f"Token obtained at: {session.token_obtained_at}") print(f"Token expires at: {session.token_expires_at}") # 2. Use token for API calls shopify.ShopifyResource.activate_session(session) shop = shopify.Shop.current() print(f"Shop: {shop.name}") # 3. Check token expiration if session.is_token_expired(buffer_seconds=300): print("Token is expired or expiring within 5 minutes") # 4. Auto-refresh if needed (before long operation) result = session.refresh_token_if_needed( scope="read_products write_products read_orders write_orders" ) if result: print("Token was refreshed proactively") # 5. Manual refresh (e.g., after permission changes) result = session.refresh_token( scope="read_products write_products read_orders write_orders" ) print(f"Token manually refreshed! New token expires in {result['expires_in']}s") Testing Comprehensive Test Coverage: ✅ Client credentials token request (success & error cases) ✅ Automatic version detection (2026-01+ vs older versions) ✅ Token expiration tracking and timestamps ✅ Token expiration checking with buffer ✅ Automatic refresh when token expired ✅ Manual force refresh ✅ Scope parameter in all OAuth methods ✅ Scope normalization (comma → space) ✅ Default behavior without scope parameter ✅ Backward compatibility with existing code Test Statistics: 15+ new test cases All existing tests pass 100% backward compatible Backward Compatibility ✓ No Breaking Changes All new features are additive and backward compatible: # Existing code works without modifications session = shopify.Session("mystore.myshopify.com", "2025-10") response = session.request_access_token(params) # Uses authorization code grant # New API version automatically uses new flow session = shopify.Session("mystore.myshopify.com", "2026-01") response = session.request_access_token() # Uses client credentials grant # Scope parameter is optional response = session.request_access_token() # No scope = all configured scopes response = session.request_access_token(scope="read_products") # Filtered scopes Migration Guide For Existing Apps (API < 2026-01) No changes required. Your code continues to work as before. For New Apps (API >= 2026-01) Option 1 - Simple (no scope filtering): shopify.Session.setup(api_key="client_id", secret="client_secret") session = shopify.Session("mystore.myshopify.com", "2026-01") response = session.request_access_token() # Gets all configured scopes Option 2 - With automatic refresh: shopify.Session.setup(api_key="client_id", secret="client_secret") session = shopify.Session("mystore.myshopify.com", "2026-01") # Get initial token session.request_access_token() # Before long operations, auto-refresh if needed session.refresh_token_if_needed() # Use session for API calls shopify.ShopifyResource.activate_session(session) Option 3 - With scope filtering (multi-API apps): shopify.Session.setup(api_key="client_id", secret="client_secret") session = shopify.Session("mystore.myshopify.com", "2026-01") # Request only Admin API scopes response = session.request_access_token( scope="read_products write_products read_orders write_orders" ) # Auto-refresh with same scopes session.refresh_token_if_needed( scope="read_products write_products read_orders write_orders" ) Implementation Details RFC 6749 Compliance: Implements OAuth 2.0 Client Credentials Grant (Section 4.4) Form-encoded request body (application/x-www-form-urlencoded) Proper error handling per OAuth 2.0 spec Security: Client credentials never exposed in URLs Tokens transmitted over HTTPS only Proper scope validation and filtering Error Handling: OAuthException for OAuth-specific errors (401, 400, etc.) Detailed error messages from Shopify included HTTP status codes preserved for debugging Checklist OAuth 2.0 Client Credentials Grant implementation (RFC 6749 Section 4.4) Automatic API version detection Token expiration tracking (token_obtained_at, token_expires_at) Token expiration checking with configurable buffer Automatic token refresh (refresh_token_if_needed) Manual token refresh (refresh_token) Scope filtering for all OAuth methods Scope normalization (comma → space) New OAuthException for OAuth errors Comprehensive test coverage (15+ tests) Updated CHANGELOG Backward compatibility maintained All existing tests pass No breaking changes Benefits This PR enables developers to: ✅ Build apps for Shopify API 2026-01+ using Client Credentials Grant ✅ Automatically handle token expiration and refresh ✅ Prevent authentication failures during long-running operations ✅ Configure multiple API types in a single Shopify app ✅ Use Customer Account API scopes alongside Admin API scopes ✅ Follow OAuth 2.0 best practices for scope filtering ✅ Seamlessly migrate from older API versions Related: Implements OAuth 2.0 support for apps created in the new Shopify Dev Dashboard, which use Client Credentials Grant instead of Authorization Code Grant for server-to-server authentication.

Open Graph Description: Complete OAuth 2.0 Client Credentials Grant Support for Shopify API 2026-01+ Overview This PR adds comprehensive OAuth 2.0 Client Credentials Grant support required for Shopify API version 2026-01 ...

X Description: Complete OAuth 2.0 Client Credentials Grant Support for Shopify API 2026-01+ Overview This PR adds comprehensive OAuth 2.0 Client Credentials Grant support required for Shopify API version 2026-01 ...

Opengraph URL: https://github.com/Shopify/shopify_python_api/pull/787

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:7948f5a1-edd9-7f56-68e5-7b95f9992459
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDDA8:1940BA:FBD52:158A38:696963AB
html-safe-nonceff4082b8f1111f06f5a73852a47301354ac4a6de564563df35c37f206f395176
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREE4OjE5NDBCQTpGQkQ1MjoxNThBMzg6Njk2OTYzQUIiLCJ2aXNpdG9yX2lkIjoiNzcyNjI4ODU1MTExNTU4MDMzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac71d23d69ebbc29c228f817d5ba751aade1a5f1e3e4488c04bab49937de9bf709
hovercard-subject-tagpull_request:3174645342
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/Shopify/shopify_python_api/pull/787/files
twitter:imagehttps://avatars.githubusercontent.com/u/27447535?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/27447535?s=400&v=4
og:image:altComplete OAuth 2.0 Client Credentials Grant Support for Shopify API 2026-01+ Overview This PR adds comprehensive OAuth 2.0 Client Credentials Grant support required for Shopify API version 2026-01 ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None48487c1ad776a7975b7132d95f4240ff3ae37cd5b8e3cb597102a4edb76738f1
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/Shopify/shopify_python_api git https://github.com/Shopify/shopify_python_api.git
octolytics-dimension-user_id8085
octolytics-dimension-user_loginShopify
octolytics-dimension-repository_id2249127
octolytics-dimension-repository_nwoShopify/shopify_python_api
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id2249127
octolytics-dimension-repository_network_root_nwoShopify/shopify_python_api
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release669463fcc54773a88c1f5a44eef6b99a5504b9c7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/Shopify/shopify_python_api/pull/787/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FShopify%2Fshopify_python_api%2Fpull%2F787%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FShopify%2Fshopify_python_api%2Fpull%2F787%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=Shopify%2Fshopify_python_api
Reloadhttps://github.com/Shopify/shopify_python_api/pull/787/files
Reloadhttps://github.com/Shopify/shopify_python_api/pull/787/files
Reloadhttps://github.com/Shopify/shopify_python_api/pull/787/files
Shopify https://github.com/Shopify
shopify_python_apihttps://github.com/Shopify/shopify_python_api
Notifications https://github.com/login?return_to=%2FShopify%2Fshopify_python_api
Fork 390 https://github.com/login?return_to=%2FShopify%2Fshopify_python_api
Star 1.4k https://github.com/login?return_to=%2FShopify%2Fshopify_python_api
Code https://github.com/Shopify/shopify_python_api
Issues 13 https://github.com/Shopify/shopify_python_api/issues
Pull requests 11 https://github.com/Shopify/shopify_python_api/pulls
Actions https://github.com/Shopify/shopify_python_api/actions
Models https://github.com/Shopify/shopify_python_api/models
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/Shopify/shopify_python_api/security
Please reload this pagehttps://github.com/Shopify/shopify_python_api/pull/787/files
Insights https://github.com/Shopify/shopify_python_api/pulse
Code https://github.com/Shopify/shopify_python_api
Issues https://github.com/Shopify/shopify_python_api/issues
Pull requests https://github.com/Shopify/shopify_python_api/pulls
Actions https://github.com/Shopify/shopify_python_api/actions
Models https://github.com/Shopify/shopify_python_api/models
Security https://github.com/Shopify/shopify_python_api/security
Insights https://github.com/Shopify/shopify_python_api/pulse
Sign up for GitHub https://github.com/signup?return_to=%2FShopify%2Fshopify_python_api%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FShopify%2Fshopify_python_api%2Fissues%2Fnew%2Fchoose
lvalicshttps://github.com/lvalics
Shopify:mainhttps://github.com/Shopify/shopify_python_api/tree/main
lvalics:feature/oauth-client-credentials-2026https://github.com/lvalics/shopify_python_api/tree/feature/oauth-client-credentials-2026
Conversation 0 https://github.com/Shopify/shopify_python_api/pull/787
Commits 5 https://github.com/Shopify/shopify_python_api/pull/787/commits
Checks 1 https://github.com/Shopify/shopify_python_api/pull/787/checks
Files changed 4 https://github.com/Shopify/shopify_python_api/pull/787/files
Feature/oauth client credentials 2026 https://github.com/Shopify/shopify_python_api/pull/787/files#top
Show all changes 5 commits https://github.com/Shopify/shopify_python_api/pull/787/files
af0a274 Add OAuth 2.0 Client Credentials with automatic API version detection lvalics Jan 14, 2026 https://github.com/Shopify/shopify_python_api/pull/787/commits/af0a2740f605469befe926f8f98e9da39accad00
7f6fc68 Add token expiration tracking and auto-refresh functionality lvalics Jan 14, 2026 https://github.com/Shopify/shopify_python_api/pull/787/commits/7f6fc682bbe2ecc8b507a1a178ef4f67f97b03ec
c085c15 feat: add scope filtering support for OAuth 2.0 Client Credentials Grant lvalics Jan 14, 2026 https://github.com/Shopify/shopify_python_api/pull/787/commits/c085c15ac2c405e68feda4b5e95b470f36fab981
1dbd0aa chore: trigger CLA check after signing lvalics Jan 14, 2026 https://github.com/Shopify/shopify_python_api/pull/787/commits/1dbd0aade6ea217e1b48c33458fe80a00a74d41b
503d5d4 chore: trigger CLA check after signing lvalics Jan 14, 2026 https://github.com/Shopify/shopify_python_api/pull/787/commits/503d5d448527f80c76db6f7b0c9dfd814a6db3b5
Clear filters https://github.com/Shopify/shopify_python_api/pull/787/files
Please reload this pagehttps://github.com/Shopify/shopify_python_api/pull/787/files
Please reload this pagehttps://github.com/Shopify/shopify_python_api/pull/787/files
CHANGELOG https://github.com/Shopify/shopify_python_api/pull/787/files#diff-ecec88c33adb7591ee6aa88e29b62ad52ef443611cba5e0f0ecac9b5725afdba
__init__.py https://github.com/Shopify/shopify_python_api/pull/787/files#diff-1bf5e3dfd3b8b8b944870eb980fef3dc288ed6fa703a0493b945f1cf440a1230
session.py https://github.com/Shopify/shopify_python_api/pull/787/files#diff-fa06ea17b3cc78cfe9a1e9ce6f95df3d4970bb1a080c26423592c719c1a7cf9f
session_test.py https://github.com/Shopify/shopify_python_api/pull/787/files#diff-51bce3aa234a6c0bde8584ab5ac8e242e779b22b4ace7fd51e40ee273fea479d
CHANGELOGhttps://github.com/Shopify/shopify_python_api/pull/787/files#diff-ecec88c33adb7591ee6aa88e29b62ad52ef443611cba5e0f0ecac9b5725afdba
View file https://github.com/Shopify/shopify_python_api/blob/503d5d448527f80c76db6f7b0c9dfd814a6db3b5/CHANGELOG
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/Shopify/shopify_python_api/pull/787/{{ revealButtonHref }}
https://github.com/Shopify/shopify_python_api/pull/787/files#diff-ecec88c33adb7591ee6aa88e29b62ad52ef443611cba5e0f0ecac9b5725afdba
shopify/__init__.pyhttps://github.com/Shopify/shopify_python_api/pull/787/files#diff-1bf5e3dfd3b8b8b944870eb980fef3dc288ed6fa703a0493b945f1cf440a1230
View file https://github.com/Shopify/shopify_python_api/blob/503d5d448527f80c76db6f7b0c9dfd814a6db3b5/shopify/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/Shopify/shopify_python_api/pull/787/{{ revealButtonHref }}
https://github.com/Shopify/shopify_python_api/pull/787/files#diff-1bf5e3dfd3b8b8b944870eb980fef3dc288ed6fa703a0493b945f1cf440a1230
Please reload this pagehttps://github.com/Shopify/shopify_python_api/pull/787/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.