Accessing non-Google APIs using oauth2client library - python

I am trying to evaluate the usage of oauth2client and oauth2 libraries on Python. We have already installed the former on our server for using some Google API.
Now I am trying to find out a way to use the same library to use external API too. I was trying to find an example to do so. However, as I read in most of the sources online, the oauth2client is predominantly for Google APIs.
The idea behind this trial is to see if we can do away with this requirement without installing oauth2 package on our server(s).
Any oauth2 and security experts may please guide me properly, as I could not find in the oauth2client documentation that this package is not supported for any external APIs using oauth for authentication.
https://oauth2client.readthedocs.io/en/latest/# This says..
oauth2client makes it easy to interact with OAuth2-protected
resources, especially those related to Google APIs
I am running on Python and I have key, secret and the url on which I can go a GET to get the required API I need. Please advise.

Related

Django app with MS Azure SAML SSO using MSAL

I have an application created using Django that uses MSAL library to authenticate with Azure AD.
As I understand, MSAL uses OAuth and so far the authentication/authorization works great. Is there a way to implement authentication using SAML instead of OAuth. I came across pysaml2 library but doesn't have sufficient documentation to integrate with Azure AD. Can someone please share your thoughts.
Is there a way to implement authentication using SAML instead of
OAuth.
No it's not possible to use SAML authentication in MSAL library.MSAL does not support SAML. It only supports OAuth / OpenID Connect.
Similar kind of request also raised on StackOverflow and Microsoft Q&A as well you can check for more information
SAML is devloped by the Security Services Technical Committee of OASIS (Organization for the Advancement of Structured Information Standards) not by Microsoft so this might be the reason SAML is not included in MSAL Library.

How to get credentials in Google AppEngine Python37

I started new app in AppEngine Python3.7 stadard.
I am trying to get credentials using the following snippet, but its failing.
Anybody able to get credentials in GAE standard Python37 ?
Input:
from google.auth import app_engine
credentials = app_engine.Credentials()
Output:
The App Engine APIs are not available
When using App Engine Standard with python 3.7, none of the google.xxx libraries are available. You have to build your own, or use standard Python libraries. This goes for: auth, users, images, search, mail, taskqueue, memcache, urlfetch, deferred, etc., and even the ndb datastore interface.
For datastore, you use google-cloud-datastore or some 3rd party.
For others, you use a standard Python library, e.g.: google.auth => rauth, google.appengine.api.memcache => python-memcached
Read more here: https://cloud.google.com/appengine/docs/standard/python3/python-differences
That page recommends Google Identity Platform or Firebase Authentication to do authorization.

Which library I should use to obtain access token?

I have a web page with Google Sign-In and I want to access user's data on behalf of the user even if he is offline.
I am looking for a suggestion for a library that I can use to obtain access token and refresh token using the authorization code that the client sent to the server.
I followed the official guide here.
In Step 7: Exchange the authorization code for an access token, the author uses oauth2client library which appears to be deprecated:
Note: oauth2client is now deprecated. No more features will be added to the libraries and the core team is turning down support. We recommend you use google-auth and oauthlib. For more details on the deprecation, see oauth2client deprecation.
So I looked at google-auth
This library provides no support for obtaining user credentials, but does provide limited support for using user credentials.
I also took a look at oauthlib, but there are many pages undocumented.
I am using Python 3.x with Flask.
Ended using Requests-OAuthlib.
pip install requests requests_oauthlib
from requests_oauthlib import OAuth2Session
oauth = OAuth2Session(client_id=GOOGLE_CLIENT_ID,
scope=GOOGLE_SCOPE,
redirect_uri='http://localhost:8000')
token = oauth.fetch_token(token_url=GOOGLE_TOKEN_URL,
code=authorization_code,
client_secret=GOOGLE_CLIENT_SECRET)

Pulling Google Drive into Command Line

Struggling to finish building out a python script intended to pull a few lines of text from 3 different columns in a Google spreadsheet.
When I run the script, I get the following error message:
File "pr_email_robot.py", line 2, in <module>
import gspread
ImportError: No module named gspread
Pats-MacBook-Pro:pr-email-robot-master patahern$
The area of code that must be off is:
import smtplib
import gspread
from gmail_variables import *
gc = gspread.login(GMAIL_USERNAME, GMAIL_PASSWORD)
wks = gc.open("PR-Command-Line-Emails").sheet1
recipients = wks.get_all_values()
I'm guessing that I have the wrong terminology to pull the Google Spreadsheet, but I can't find anything online about what to put in place of "gspread"
Thanks in advance for your help!
Have you tried using Google Fusion Tables (still in beta)? You can query Google Fusion Tables' Rest API using SQL syntax and urllib's urllib.request.urlopen() to issue GET and POST requests. If you are heart set on using Google Sheets, the Google Sheets API looks like it functions in much of the same way as Google Fusion Tables REST API. Meaning, you can still use the built in urllib Python library to issue GET and POST requests to the Sheets API.
It may also be helpful to note that Google has posted a Getting Started in Python Guide for the Google Sheets API. The example shown there, has no mention of any "gspread" imports.
You need to make sure you have the gspread module installed somewhere your Python installation will find it.
If you have pip:
pip install gspread
will make sure that it's installed.
ALSO
Gspread no longer supports using email/login for authentication, and relies on OAuth2 for authentication.
Check out how to set that up here.
Then check out the gspread docs for how to access info from your sheet!

Workarounds to get Google sign-in functioning with Python 2.6 and pyOpenSSL 0.10-2

I'm trying to get Google sign-in working using their Python API but the server I'm on (4UHosting) has Python 2.6 and pyOpenSSL 0.10-2 (5-years old).
This means that the API's call to OpenSSL.crypto.verify() fails as it doesn't exist in this version.
I can't install these myself, even --self as they require compiler use which I don't have. The admins are reluctant to install any updates that are not vetted. They won't install pyOpenSSL or Python 2.7 locally just for me. I can't find documentation from pyOpenSSL 0.10-2 that would have an equivalent function to verify().
I'm looking for some suggestions as where to head from here.
Any suggestions would be greatly appreciated,
Cyrille
A few ideas:
You could directly make your API calls to the Google API Endpoints instead of using the Python client library, for example, the token info endpoint can be used to verify tokens
You could do sign-in operations client-side and transfer data to your server once a session is attached
You could use another language (e.g. Ruby) for the sign-in operations

Categories