Почему oauth2 url не открывается на стороне клиента?
У меня проблема с моим google drive 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&[..............]
Но, когда я развертываю свой фронт (приложение angular) и свой бэк (приложение django) на удаленном сервере, используя docker. Возникает проблема.
1 - Если мой token.json уже сгенерирован : Он работает очень хорошо.
1.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- почему перенаправление происходит на localhost, а не на мой ip-адрес?
Танск много
flow = InstalledAppFlow.from_client_secrets_file(
'code_clientXXX.json',
SCOPES)
Класс google_auth_oauthlib.flow.InstalledAppFlow используется для установленных приложений. Этот поток полезен для локальной разработки или приложений, установленных на настольной операционной системе. См. раздел OAuth 2.0 для установленных приложений.
.
Ваш код предназначен для запуска в качестве установленного приложения, это означает, что экран согласия будет открыт на машине, на которой запущен код. Если вы попытаетесь сделать это глубоко в docker, он попытается открыть окно браузера в контейнере docker, что не сработает, там нет никого, кто мог бы это увидеть.