Skip to content

Instantly share code, notes, and snippets.

Ib Lundgren ib-lundgren

Block or report user

Report or block ib-lundgren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ib-lundgren
ib-lundgren / refresh_example.py
Last active May 29, 2017
Work in progress example of how to do oauth 2 token refresh in a web application. Requires python modules oauthlib master - pip install -e git+https://github.com/idan/oauthlib#egg=oauthlib requests-oauthlib latest from pip (don't think master is needed) flask & requests
View refresh_example.py
from json import dumps
from flask import Flask, request, redirect, session, url_for
from flask.json import jsonify
from requests_oauthlib import OAuth2Session
app = Flask(__name__)
# Ignore this, only used as basic doc string template creator.
def docstring_templator(f):
@ib-lundgren
ib-lundgren / gmail.py
Created Sep 25, 2013
How to fetch emails from GMail using an OAuth 2 Bearer token and GMails SASL XOAuth2 mechanism.
View gmail.py
"""Fetching the latest GMail email using OAuth 2 and IMAP.
Requires requests-oauthlib, which is available on pypi.
Includes a basic SASL XOAUTH2 authentication method for imaplib.
"""
# Credentials you get from registering a new web application in Google API Console
client_id = 'your-id.apps.googleusercontent.com'
client_secret = 'your secret'
redirect_uri = 'your callback uri'
@ib-lundgren
ib-lundgren / github_flask_oauth2.py
Created Sep 10, 2013
Example of how to use Flask with requests-oauthlib to fetch a GitHub user profile using an OAuth 2 token.
View github_flask_oauth2.py
from requests_oauthlib import OAuth2Session
from flask import Flask, request, redirect, session, url_for
from flask.json import jsonify
import os
app = Flask(__name__)
# This information is obtained upon registration of a new GitHub
client_id = "<your client key>"
View Flask and request_oauthlib example using twitter
import requests
from requests_oauthlib import OAuth1
from flask import Flask, request, redirect, session
from urlparse import parse_qs
import os
app = Flask(__name__)
# This information is obtained upon registration of a new client on twitter
key = u"<your client key>"
@ib-lundgren
ib-lundgren / oauth2_webapp_demo.py
Created Jul 9, 2012
OAuth2 webapp with OAuthLib
View oauth2_webapp_demo.py
# Non magic version, client is only used to append tokens
# All other actions are explicit
import requests
from requests.auth import AuthBase
from oauthlib.oauth2.draft25 import WebApplicationClient
from oauthlib.common import urldecode
# Very basic auth, only used to append tokens to requests
@ib-lundgren
ib-lundgren / gist:3070603
Created Jul 8, 2012
Bit of magic OAuth2
View gist:3070603
# The slightly magic version, extra requests are made to obtain token
# and users must fetch values from client when saving them to a db
import requests
from requests.auth import AuthBase
from oauthlib.oauth2.draft25 import WebApplicationClient
from oauthlib.common import urldecode, generate_token
class OAuth2WebApp(WebApplicationClient, AuthBase):
@ib-lundgren
ib-lundgren / gist:3070602
Created Jul 8, 2012
Explicit no magic OAuth2
View gist:3070602
# Non magic version, client is only used to append tokens
# All other actions are explicit
import requests
from requests.auth import AuthBase
from oauthlib.oauth2.draft25 import WebApplicationClient
from oauthlib.common import urldecode
class OAuth2WebApp(WebApplicationClient, AuthBase):
@ib-lundgren
ib-lundgren / gist:2584789
Created May 3, 2012
OAuth1 using requests, OAuthLib and RSA signatures
View gist:2584789
import requests
from requests.auth import OAuth1
from oauthlib.oauth1.rfc5849 import SIGNATURE_RSA
client_key = u'...'
# You need to register your key with the OAuth provider first,
# in this case Google at https://accounts.google.com/ManageDomains
key = open("your_rsa_key.pem").read()
You can’t perform that action at this time.