Python google_auth_oauthlib.flow.InstalledAppFlow.from_client_config() Examples
The following are 5
code examples of google_auth_oauthlib.flow.InstalledAppFlow.from_client_config().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google_auth_oauthlib.flow.InstalledAppFlow
, or try the search function
.
Example #1
Source File: oauth_client.py From s3ql with GNU General Public License v3.0 | 8 votes |
def main(args=None): if args is None: args = sys.argv[1:] options = parse_args(args) setup_logging(options) # We need full control in order to be able to update metadata # cf. https://stackoverflow.com/questions/24718787 flow = InstalledAppFlow.from_client_config( client_config={ "installed": { "client_id": OAUTH_CLIENT_ID, "client_secret": OAUTH_CLIENT_SECRET, "redirect_uris": ["http://localhost", "urn:ietf:wg:oauth:2.0:oob"], "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token" } }, scopes=['https://www.googleapis.com/auth/devstorage.full_control']) credentials = flow.run_local_server(open_browser=True) print('Success. Your refresh token is:\n', credentials.refresh_token)
Example #2
Source File: wrapper.py From starthinker with Apache License 2.0 | 6 votes |
def CredentialsFlowWrapper(client, credentials_only=False, **kwargs): # relax scope comparison, order and default scopes are not critical os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1' # parse credentials from file or json if RE_CREDENTIALS_JSON.match(client): client_json = json.loads(client) else: with open(client, 'r') as json_file: client_json = json.load(json_file) if credentials_only: return client_json else: if 'installed' in client_json: flow = InstalledAppFlow.from_client_config(client_json, APPLICATION_SCOPES, **kwargs) else: flow = Flow.from_client_config(client_json, APPLICATION_SCOPES, **kwargs) flow.user_agent = APPLICATION_NAME return flow
Example #3
Source File: __init__.py From Pipulate with MIT License | 5 votes |
def login(): client_id = "769904540573-knscs3mhvd56odnf7i8h3al13kiqulft.apps.googleusercontent.com" client_secret = "D2F1D--b_yKNLrJSPmrn2jik" environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = "1" # Don't use in Web apps scopes = ["https://spreadsheets.google.com/feeds/", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/gmail.modify", "https://www.googleapis.com/auth/analytics.readonly", "https://www.googleapis.com/auth/webmasters.readonly", "https://www.googleapis.com/auth/yt-analytics.readonly", "https://www.googleapis.com/auth/youtube.readonly"] client_config = { "installed": { "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token", "redirect_uris": ["urn:ietf:wg:oauth:2.0:oob"], "client_id": client_id, "client_secret": client_secret } } flow = InstalledAppFlow.from_client_config(client_config, scopes) credentials = flow.run_console() credentials.access_token = credentials.token with open("credentials.pickle", "wb") as output_file: pickle.dump(credentials, output_file) return credentials
Example #4
Source File: generate_refresh_token.py From googleads-python-lib with Apache License 2.0 | 5 votes |
def main(client_id, client_secret, scopes): """Retrieve and display the access and refresh token.""" client_config = ClientConfigBuilder( client_type=ClientConfigBuilder.CLIENT_TYPE_WEB, client_id=client_id, client_secret=client_secret) flow = InstalledAppFlow.from_client_config( client_config.Build(), scopes=scopes) # Note that from_client_config will not produce a flow with the # redirect_uris (if any) set in the client_config. This must be set # separately. flow.redirect_uri = _REDIRECT_URI auth_url, _ = flow.authorization_url(prompt='consent') print('Log into the Google Account you use to access your AdWords account ' 'and go to the following URL: \n%s\n' % auth_url) print('After approving the token enter the verification code (if specified).') code = input('Code: ').strip() try: flow.fetch_token(code=code) except InvalidGrantError as ex: print('Authentication has failed: %s' % ex) sys.exit(1) print('Access token: %s' % flow.credentials.token) print('Refresh token: %s' % flow.credentials.refresh_token)
Example #5
Source File: generate_refresh_token.py From googleads-python-lib with Apache License 2.0 | 5 votes |
def main(client_id, client_secret, scopes): """Retrieve and display the access and refresh token.""" client_config = ClientConfigBuilder( client_type=ClientConfigBuilder.CLIENT_TYPE_WEB, client_id=client_id, client_secret=client_secret) flow = InstalledAppFlow.from_client_config( client_config.Build(), scopes=scopes) # Note that from_client_config will not produce a flow with the # redirect_uris (if any) set in the client_config. This must be set # separately. flow.redirect_uri = _REDIRECT_URI auth_url, _ = flow.authorization_url(prompt='consent') print('Log into the Google Account you use to access your Ad Manager account' 'and go to the following URL: \n%s\n' % (auth_url)) print('After approving the token enter the verification code (if specified).') code = input('Code: ').strip() try: flow.fetch_token(code=code) except InvalidGrantError as ex: print('Authentication has failed: %s' % ex) sys.exit(1) print('Access token: %s' % flow.credentials.token) print('Refresh token: %s' % flow.credentials.refresh_token)