2

using this quickstart.ipynb I'm getting this error You can’t sign in because "myapp" sent an invalid request. You can try again later, or contact the developer about this issue. Learn more about this error If you are a developer of myapp, see error details. Error 400: invalid_request

Error 400: invalid_request The out-of-band (OOB) flow has been blocked in order to keep users secure. Follow the Out-of-Band (OOB) flow Migration Guide linked in the developer docs below to migrate your app to an alternative method. Request details: redirect_uri=urn:ietf:wg:oauth:2.0:oob

This is the code which is running

from apiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow

CLIENT_CONFIG = {
'installed': {
'client_id':'----------------------------------------------------------',
'client_secret': '------------------------------------------------------',
'auth_uri':'https://accounts.google.com/o/oauth2/auth',
'token_uri':'https://oauth2.googleapis.com/token'
}
}
SCOPES = ['https://www.googleapis.com/auth/androidmanagement']

flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES)
credentials = flow.run_console()

androidmanagement = build('androidmanagement', 'v1', credentials=credentials)

print('\nAuthentication succeeded.')
Vinith Jain
  • 35
  • 1
  • 8

2 Answers2

2

Since Google has deprecated OOB

You have to use the new method run_local_server() if you are using the google_auth_oauthlib package

Replace the line

credentials = flow.run_console()

to

credentials = flow.run_local_server()
0xWise
  • 79
  • 1
  • 6
0

The out-of-band (OOB) flow has been blocked.

Use the below code Replace your 'your client id' and 'your client secret'

from apiclient.discovery import build
from google_auth_oauthlib.flow import Flow

# This is a public OAuth config that you can use to run this guide.
# However, use different credentials when building your own solution.
CLIENT_CONFIG = {
  'web': {
    'client_id':'your client id',
    'auth_uri':'https://accounts.google.com/o/oauth2/auth',
    'token_uri':'https://oauth2.googleapis.com/token',
'auth_provider_x509_cert_url':'https://www.googleapis.com/oauth2/v1/certs',
'client_secret':'your client secret'
  }
}
SCOPES = ['https://www.googleapis.com/auth/androidmanagement']
CALLBACK_URL = 'https://google.github.io/android-management-api-    samples/oauth_callback.html'

# Run the OAuth flow.
flow = Flow.from_client_config(CLIENT_CONFIG, SCOPES)
flow.redirect_uri = CALLBACK_URL
auth_url, _ = flow.authorization_url()
print('Please visit this URL to authorize this application:     {}'.format(auth_url))

code = input('Enter the authorization code: ')
flow.fetch_token(code=code)

# Create the API client.
androidmanagement = build('androidmanagement', 'v1',     credentials=flow.credentials)

print('\nAuthentication succeeded.')

full link for Android Management API Quick Start https://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb

MRazaImtiaz
  • 1,964
  • 1
  • 13
  • 23