Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

115 open能否增加使用自己的客户端 #8173

Closed
Yicons opened this issue Mar 19, 2025 · 6 comments
Closed

115 open能否增加使用自己的客户端 #8173

Yicons opened this issue Mar 19, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@Yicons
Copy link

Yicons commented Mar 19, 2025

Please make sure of the following things

  • I have read the documentation.
  • I'm sure there are no duplicate issues or discussions.
  • I'm sure this feature is not implemented.
  • I'm sure it's a reasonable and popular requirement.

Description of the feature / 需求描述

像阿里open一样用自己的AppID | AppKey从而进行授权

Suggested solution / 实现思路

No response

Additional context / 附件

No response

@Yicons Yicons added the enhancement New feature or request label Mar 19, 2025
Copy link

您提到的功能请求是关于在 Alist 中增加使用自己的客户端进行授权的功能,类似于阿里 open 的方式,使用自己的 AppID 和 AppKey。这个请求目前还没有实现。

如果您希望此功能被考虑加入,建议您在 GitHub 上的 AlistGo/alist 仓库中创建一个功能请求(Feature Request)以便开发者团队能够看到并评估这个需求的合理性和受欢迎程度。

如果您有任何其他问题或需要进一步的帮助,请随时告诉我。

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

@ZuesTao
Copy link

ZuesTao commented Mar 19, 2025

建议开发大大们看到这个需求,让我们早日用上自己的AppID和Appkey

@pongfcnkl
Copy link

本来就可以吧,只要你自己会写授权代码就行了

@creeper2020
Copy link

creeper2020 commented Mar 20, 2025

import requests
import hashlib
import base64
import secrets
import qrcode
from io import BytesIO
from PIL import Image

# 常量定义
APP_ID = ""  # 替换为你的 APP ID
DEVICE_CODE_URL = "https://passportapi.115.com/open/authDeviceCode"
ACCESS_TOKEN_URL = "https://passportapi.115.com/open/deviceCodeToToken"

def generate_code_verifier_and_challenge():
    """生成 code_verifier 和 code_challenge"""
    code_verifier = secrets.token_urlsafe(64)
    code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode('utf-8')).digest()).decode('utf-8').rstrip('=')
    return code_verifier, code_challenge

def get_device_code(code_verifier, code_challenge):
    """获取设备码和二维码内容"""
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = {
        'client_id': APP_ID,
        'code_challenge': code_challenge,
        'code_challenge_method': 'sha256'
    }
    response = requests.post(DEVICE_CODE_URL, headers=headers, data=data)
    response.raise_for_status()
    return response.json()

def get_access_token(uid, code_verifier):
    """获取 access_token"""
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = {
        'uid': uid,
        'code_verifier': code_verifier
    }
    response = requests.post(ACCESS_TOKEN_URL, headers=headers, data=data)
    response.raise_for_status()
    return response.json()

def show_qrcode_image(qrcode_content):
    """显示二维码图像"""
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=4,
    )
    qr.add_data(qrcode_content)
    qr.make(fit=True)

    img = qr.make_image(fill_color="black", back_color="white")
    img_byte_arr = BytesIO()
    img.save(img_byte_arr, format='PNG')
    img_byte_arr = img_byte_arr.getvalue()
    image = Image.open(BytesIO(img_byte_arr))
    image.show()

def main():
    # 1. 生成 code_verifier 和 code_challenge
    code_verifier, code_challenge = generate_code_verifier_and_challenge()
    print(f"Generated code_verifier: {code_verifier}")

    # 2. 获取设备码和二维码信息
    device_code_data = get_device_code(code_verifier, code_challenge)
    print(f"Device Code Data: {device_code_data}")
    uid = device_code_data['data']['uid']

    # 3. 显示二维码
    show_qrcode_image(device_code_data['data']['qrcode'])

    # 4. 等待用户手动确认
    input("请使用 115 客户端扫描二维码并确认登录,然后按 Enter 键继续...")

    # 5. 尝试获取 access_token
    try:
        token_data = get_access_token(uid, code_verifier)
        print(f"Access Token Data: {token_data}")
        if 'data' in token_data and 'access_token' in token_data['data']:
            print(f"Access Token: {token_data['data']['access_token']}")
        else:
            print("Access Token not found in response.")

    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

自己部署就行了

@Yicons
Copy link
Author

Yicons commented Mar 20, 2025

import requests
import hashlib
import base64
import secrets
import qrcode
from io import BytesIO
from PIL import Image

# 常量定义
APP_ID = ""  # 替换为你的 APP ID
DEVICE_CODE_URL = "https://passportapi.115.com/open/authDeviceCode"
ACCESS_TOKEN_URL = "https://passportapi.115.com/open/deviceCodeToToken"

def generate_code_verifier_and_challenge():
    """生成 code_verifier 和 code_challenge"""
    code_verifier = secrets.token_urlsafe(64)
    code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode('utf-8')).digest()).decode('utf-8').rstrip('=')
    return code_verifier, code_challenge

def get_device_code(code_verifier, code_challenge):
    """获取设备码和二维码内容"""
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = {
        'client_id': APP_ID,
        'code_challenge': code_challenge,
        'code_challenge_method': 'sha256'
    }
    response = requests.post(DEVICE_CODE_URL, headers=headers, data=data)
    response.raise_for_status()
    return response.json()

def get_access_token(uid, code_verifier):
    """获取 access_token"""
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = {
        'uid': uid,
        'code_verifier': code_verifier
    }
    response = requests.post(ACCESS_TOKEN_URL, headers=headers, data=data)
    response.raise_for_status()
    return response.json()

def show_qrcode_image(qrcode_content):
    """显示二维码图像"""
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=4,
    )
    qr.add_data(qrcode_content)
    qr.make(fit=True)

    img = qr.make_image(fill_color="black", back_color="white")
    img_byte_arr = BytesIO()
    img.save(img_byte_arr, format='PNG')
    img_byte_arr = img_byte_arr.getvalue()
    image = Image.open(BytesIO(img_byte_arr))
    image.show()

def main():
    # 1. 生成 code_verifier 和 code_challenge
    code_verifier, code_challenge = generate_code_verifier_and_challenge()
    print(f"Generated code_verifier: {code_verifier}")

    # 2. 获取设备码和二维码信息
    device_code_data = get_device_code(code_verifier, code_challenge)
    print(f"Device Code Data: {device_code_data}")
    uid = device_code_data['data']['uid']

    # 3. 显示二维码
    show_qrcode_image(device_code_data['data']['qrcode'])

    # 4. 等待用户手动确认
    input("请使用 115 客户端扫描二维码并确认登录,然后按 Enter 键继续...")

    # 5. 尝试获取 access_token
    try:
        token_data = get_access_token(uid, code_verifier)
        print(f"Access Token Data: {token_data}")
        if 'data' in token_data and 'access_token' in token_data['data']:
            print(f"Access Token: {token_data['data']['access_token']}")
        else:
            print("Access Token not found in response.")

    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

自己部署就行了

非常感谢~

@Yicons Yicons closed this as completed Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants