All,
I am trying to build a library for onedrive.
Not to give too much detail but I have constructed the request and if I call this from a browser everything works fine, and i eventually get a json response.
https://login.live.com/oauth20_authorize.srf?client_id=CLIENT_ID&scope=wl.signin%20wl.basic&response_type=code&redirect_uri=http://someaddress.com/redirect.html
My problem is that I cannot get the authorization code in python using urllib2 and geturl() method as the redirect that yields the code is not seen by urllib2.
When I call the geturl() method I get the original url, not the redirect url containing the code.
Regards,
Frage
With the release of the OneDrive API there is pretty solid documentation on how to implement the OAuth 2.0 standard from scratch. Following what that doc lays out should make the authentication flow in your application pretty straight-forward.
Related
I have a Python FastAPI Backend which gives me an endpoint in order to retrieve some oAuth data. The Endpoint works when i put it manually in my Browser. It first does a redirect retrieves an accessToken which it then adds to a second link and opens it. So the functionality works. Now i'm a bit stuck on how to get this data in my Frontend. I tried a GET request on the original endpoint but then get the response with the redirect link. What would be a clever way to handle this? I would like to store the data in the Frontend in order to manipulate it
Thanks for helping me!
After doing many OAuth2 interactions, I recommend you use a library; OAuth2 flow is fairly complicated with the interactions between Client, Backend, Identification, & Authorization servers. Using a library helps ensure you are doing all the key swaps properly and securely; Also it will save you lots of time :).
Here is a library I would use in your shoes; https://github.com/manfredsteyer/angular-oauth2-oidc
I have a java Google App Engine restful server implemented via Jersey. I am able to make successful GET, POST, PUT, and DELETEs using Postman, a browser based curl like program, when signed into my Google account in the browser session.
Now I am trying to make similar calls in a Python script using the Requests library.
payload = "{\"key\":1, \"dateOpened\":2341342, \"dateClosed\":0, \"description\":\"test\", \"urgency\":2, \"staus\":1}"
r = requests.post("http://localhost:8080/ticket", params=payload)
print r.status_code
When I do this I get a redirect which I am unsure how to handle.
com.google.apphosting.utils.jetty.AppEngineAuthentication$AppEngineAuthenticator authenticate
Got /ticket but no one was logged in, redirecting.
How am I able to make it log in as well using the Requests library? I would like to continue using the Requests library if possible due to its simplicity, but I am a new to using it.
Thanks.
I am trying to find the easiest way how to use Facebook Graph API using my favorite Requests library. The problem is, all examples I found are about getting user access token, about redirects and user interaction.
All I need is only application access token. I do not handle any non-public data, so I need no user interaction and as my final app is supposed to be command-line script, no redirects are desired.
I found something similar here, but it seems to be everything but elegant. Moreover, I would prefer something using Requests or Requests-OAuth2. Or maybe there is library for that? I found Requests-Facebook and Facepy (both Requests based), but again, all examples are with redirection, etc. Facepy does not handle authorization at all, it just accepts your token and it is up to you to get it somehow.
Could someone, please, provide a short, sane, working example how to get just the application access token?
Following https://developers.facebook.com/docs/technical-guides/opengraph/publishing-with-app-token/:
import requests
r = requests.get('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=123&client_secret=XXX')
access_token = r.text.split('=')[1]
print access_token
(using the correct values for client_id and client_secret) gives me something that looks like an access token.
If you just need a quick/small request, you can manually cut and paste the access token from here into you code: https://developers.facebook.com/tools/explorer
Note: Unlike Richard Barnett's answer, you'll need to regenerate the code manually from the graph api explorer every time you use it.
I'm using python-oauth2 to authenticate API calls to Dropbox's API.
There are two problems I'm having:
I don't know how to provide a callback function to OAuth. I tried making the request as follows:
resp, content = client.request(request_token_url,\
"POST",body=urllib.urlencode({'oauth_callback':callbackURL}))
However, the function at callbackURL is not called.
At the moment, I've just modified the example code given in the README for python-oauth2, and I've managed to redirect the user to the Dropbox authentication page. However, I've written no code to explicitly sign my requests. Is that being done by the module, or are the requests I am making just unsigned? If its the latter, I'm really confused as to how things are working.
Help much appreciated. Thanks!
--Edit--
So I was reading the API docs, and the authorization URL takes two parameters - one is the access_token and the second is oauth_callback. I managed to created a URL that had these two parameters, and now, once the user authenticates my app, they are successfully redirected to my website. However, this seems like a very crude hack, and I'd love to learn to do this in a better way.
I have a requirement to build a client for Shopify's API, building it in Python & Django.
I've never done it before and so I'm wondering if someone might advise on a good starting point for the kinds of patterns and techniques needed to get a job like this done.
Here's a link to the Shopify API reference
Thanks.
Your question is somewhat open-ended, but if you're new to Python or API programming, then you should get a feel for how to do network programming in Python, using either the urllib2 or httplib modules that come with more recent versions of Python. Learn how to initiate a request for a page and read the response into a file.
Here is an overview of the httplib module in Python documentation:
http://docs.python.org/library/httplib.html
After you've managed to make page requests using the GET HTTP verb, learn about how to make POST requests and how to add headers, like Content-Type, to your request. When communicating with most APIs, you need to be able to send these.
The next step would be to get familiar with the XML standard and how XML documents are constructed. Then, play around with different XML libraries in Python. There are several, but I've always used xml.dom.minidom module. In order to talk to an API, you'll probably need to know to create XML documents (to include in your requests) and how to parse content out of them. (to make use of the API's responses) The minidom module allows a developer to do both of these. For your reference:
http://docs.python.org/library/xml.dom.minidom.html
Your final solution will likely put both of these together, where you create an XML document, submit it as content to the appropriate Shopify REST API URL, and then have your application deal with the XML response the API sends back to you.
If you're sending any sensitive data, be sure to use HTTPS over port 443, and NOT HTTP over port 80.
I have been working on a project for the last few months using Python and Django integrating with Shopify, built on Google App Engine.
Shopify has a valuable wiki resource, http://wiki.shopify.com/Using_the_shopify_python_api. This is what I used to get a good handle of the Shopify Python API that was mentioned, https://github.com/Shopify/shopify_python_api.
It will really depend on what you are building, but these are good resources to get you started. Also, understanding the Shopify API will help when using the Python API for Shopify.
Shopify has now released a Python API client: https://github.com/Shopify/shopify_python_api
I think you can find some inspiration by taking a look at this:
http://bitbucket.org/jespern/django-piston/wiki/Home
Although it is directly opposite what you want to do (Piston is for building APIs, and what you want is to use an API) it can give you some clues on common topics.
I could mention, of course, reading obvious sources like the Shopify developers forum:
http://forums.shopify.com/categories/9
But I guess you already had it in mind :)
Cheers,
H.