Metadata-Version: 2.4
Name: snowland-authsdk
Version: 0.2.0
Summary: snowland-authsdk, oauth 2.0 framework for Snowland.ltd
Home-page: https://gitee.com/snowlandltd/snowland-auth-sdk-python
Author: A.Star
Author-email: astar@snowland.ltd
Maintainer: A.Star
Maintainer-email: astar@snowland.ltd
License: Apache v2.0
Platform: all
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: Implementation
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyjwt
Requires-Dist: snowland-smx>=1.0.0
Requires-Dist: easydict
Requires-Dist: decorator
Requires-Dist: snowland-http>=0.2.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: maintainer
Dynamic: maintainer-email
Dynamic: platform
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# snowland-auth-sdk-python
[![Version](https://img.shields.io/badge/Python-3.8|3.9|3.10|3.11|3.12-yellowgreen.svg)]()
[![License](http://img.shields.io/:License-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
[![PyPI Version](https://img.shields.io/pypi/v/snowland-authsdk)](https://gitee.com/snowlandltd/snowland-auth-sdk-python)
[![Downloads](https://img.shields.io/pypi/dm/snowland-authsdk?cacheSeconds=86400)](https://pypi.org/project/snowland-authsdk)


Providing unified third-party OAuth login (GitHub, Gitee, CSDN, WeChat, WeChat Work, Alipay, Aliyun, 1688, etc.) as well as Snowland's native authorization.

## Features
- Supports Snowland's own authorization system as well as multi-platform third-party OAuth login
- Unified `BaseOAuthClient` abstraction with consistent interfaces across platforms
- Synchronous / asynchronous HTTP calls powered by `snowland-http`
- No dependency on `requests` / `astartool`; only the standard library and `snowland-http` are required

## Supported third-party platforms
GitHub, Gitee, CSDN, WeChat, WeChat Work, Alipay, Aliyun, 1688, Snowland

## Installation
```bash
pip install snowland-authsdk
```

## Usage
### Option 1: Snowland native authorization (legacy interface)
1. First, register an account on the snowland-auth website.
2. Create an application on the snowland-auth website to obtain the application's `access_key` and `access_secret`.
3. As shown in the demo:
- Create an OAuth object

```python
from snowland_authsdk.login import OAuth
access_key = 'tuxf517fqdserop68z1m3zmf6bs6tkrf'
access_secret = '2446ea7d1722da461052d547268480b5aca159a781ccba27908a3acde887889c'
app = OAuth(access_key, access_secret)
```

- Redirect the URL so that the user can send a request to the third-party server
```python
res = app.oauth_authorize(**param, **user)
```
- Obtain the user's `code`, and use it to apply for a token from the third-party server
```python
res = app.oauth_access_token(**{"code": code, "method":'post'})
```
- Use the token to request data from the third-party server
```python
res = app.oauth_access_token(**{"code": code, "method": 'get'})
```

### Option 2: Third-party OAuth login (new module)
Using GitHub as an example:

```python
from snowland_authsdk.oauth import GitHubOAuthClient

client = GitHubOAuthClient(
    client_id='your_client_id',
    client_secret='your_client_secret',
    redirect_uri='https://your-app/callback',
)
# 1. Redirect the user to the authorization page
authorize_url = client.get_authorize_url(state='random_state')
# 2. After callback, exchange the code for user info
user = client.get_userinfo(code='code_from_callback')
```

All platform clients live under `snowland_authsdk.oauth`, e.g.
`GitHubOAuthClient`, `GiteeOAuthClient`, `WeChatOAuthClient`,
`WeChatWorkOAuthClient`, `AlipayOAuthClient`, `AliyunOAuthClient`,
`Alibaba1688OAuthClient`, `CsdnOAuthClient`, `SnowlandOAuthClient`.

## Adoption Registry
More companies adopting this project are welcome to register at the registration address. Registration is only for product promotion.

The following companies or organizations have directly or indirectly used this project:

- A.Star Algorithm Group
- Hebei Snowland Network Technology Co., Ltd.

...


## Copyright and License
This product is open source and free, and will continue to provide technical support. Individual or enterprise users are free to access and use.

Licensed under the Apache v2.0 License (Apache 2.0).
Copyright (c) 2019-present, Snowland Co,.Ltd

The product is open source and free of charge, and we will continue to provide technical support. Individuals and enterprises may freely integrate and use it.

## Donate
No matter how much the amount is, it is enough to express your thought. Thank you very much ：） To donate

No matter how much the amount is, it is enough to express your appreciation. Thank you very much ：）
