为什么我的客户端没有打开 oauth2 url?

Why oauth2 url is not opened on my client side?

我的 google 驱动器 oauth2 有问题。

我有这个代码:

def getService(creds):

    service = build('drive', 'v3', credentials=creds)
    return service


def getCredentials():

    # If modifying these scopes, delete the file token.json.
    SCOPES = ['https://www.googleapis.com/auth/drive']
    """Shows basic usage of the Drive v3 API.
        Prints the names and ids of the first 10 files the user has access to.
        """
    creds = None
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:

            creds.refresh(Request())
        else:

            flow = InstalledAppFlow.from_client_secrets_file(
                'code_clientXXX.json',
                SCOPES)

            creds = flow.run_local_server(port=0)
            print(creds)
        # Save the credentials for the next run
        with open('token.json', 'w') as token:
            token.write(creds.to_json())
    return creds

当我在 localhost 中 运行 时,我工作得很好,这个 url 会在我的浏览器上自动打开: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=XXXX&[..............]

但是,当我使用 docker 在远程服务器上部署前端(angular 应用程序)和后端(django 应用程序)时。有问题。

1 - 如果我的 token.json 已经生成:效果很好。

2 - 如果我的 token.json 尚未生成:客户端不会询问任何内容。

如果我检查 django 日志:

sudo docker logs c289011c7be6
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=XXX-XXX.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A46523%2F&sc
ope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=XXX&access_type=offline

1- 为什么这个 url 没有在我的客户端打开

2- 为什么重定向是本地主机而不是我的 ip 地址?

非常感谢

 flow = InstalledAppFlow.from_client_secrets_file(
            'code_clientXXX.json',
            SCOPES)

Oauth.md

The google_auth_oauthlib.flow.InstalledAppFlow class is used for installed applications. This flow is useful for local development or applications that are installed on a desktop operating system. See OAuth 2.0 for Installed Applications.

您的代码旨在 运行 作为已安装的应用程序,这意味着同意屏幕将在代码 运行 正在打开的机器上打开。如果您尝试将其深入 docker 将尝试在 docker 容器中打开浏览器 window,但该容器无法正常工作,那里没有人可以看到它。