Exemplo n.º 1
0
def configured_google_client():
    google_auth = GoogleClient(
        client_id=app.config["GOOGLE_OAUTH2_CLIENT_ID"],
        client_secret=app.config["GOOGLE_OAUTH2_CLIENT_SECRET"],
        redirect_uri=app.config["GOOGLE_OAUTH2_REDIRECT_URI"],
    )
    return google_auth
Exemplo n.º 2
0
def test2():
    from requests_oauth2.services import GoogleClient
    google_auth = GoogleClient(
        client_id="your-google-client-id",
        client_secret="super-secret",
        redirect_uri="http://localhost:5000/google/oauth2callback",
    )
    authorization_url = google_auth.authorize_url(
        scope=["email"],
        response_type="code",
    )
    code = get_request_parameter("code")  # this depends on your web framework!
    data = google_auth.get_token(
        code=code,
        grant_type="authorization_code",
    )
    session["access_token"] = data["access_token"]
Exemplo n.º 3
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken

google_auth = GoogleClient(
    client_id=("488526633771-4jb5b2vsckq58it9nggon8n3v0lblr29"
               ".apps.googleusercontent.com"),
    client_secret="GwP7kmTDGcsJKfuyDup4oLB6",
    redirect_uri="http://*****:*****@app.route('/', methods=['GET', 'POST'])
def index():
    return render_template('index.html')


@app.route('/login')
def login():
    if not session.get("access_token"):
        return redirect("/oauth2callback")
    with requests.Session() as s:
        s.auth = OAuth2BearerToken(session["access_token"])
        r = s.get(
            "https://www.googleapis.com/plus/v1/people/me?access_token={}".
            format(session.get("access_token")))
    r.raise_for_status()
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from flask import Flask, request, redirect, session, Response


app = Flask(__name__)
app.secret_key = os.environ.get("SECRET_KEY") or os.urandom(20)

config = yaml.load(open("conf.yaml"),Loader=yaml.FullLoader)
client_id = config["google-oauth"][0]["client_id"]
client_secret = config["google-oauth"][0]["client_secret"]
redirect_uri = config["google-oauth"][0]["redirect_uri"]
domains = config["google-oauth"][0]["domains"]
emails = config["google-oauth"][0]["emails"]

google_auth = GoogleClient(client_id=client_id,client_secret=client_secret,redirect_uri=redirect_uri)

def checkpermissions(email):
    if email.split("@")[1] in domains or email in emails:
        return True
    return False

@app.route("/google-login")
def login():
    url = google_auth.authorize_url(scope=["profile", "email"],response_type="code",)
    html = "<a href=\"{}\">Login</a>".format(url)
    return html

@app.route("/google-auth")
def google_index():
    if not session.get("access_token"):
Exemplo n.º 5
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from .misc import findstudent

google_auth = GoogleClient(
    client_id=("624093337065-fqd6k7v5sqgj1l10kit6dhd6qofq8jat"
               ".apps.googleusercontent.com"),
    client_secret="9UEX16NlzET-aPgdntBy7Bfi",
    redirect_uri="https://computerinv-216303.appspot.com/oauth2callback"
    # "http://*****:*****@app.route('/')
def index():
    return render_template("index.html")


@app.route('/login')
def login():
    if not session.get("access_token"):
        return redirect("/oauth2callback")
    with requests.Session() as s:
        s.auth = OAuth2BearerToken(session["access_token"])
        r = s.get(
            "https://www.googleapis.com/plus/v1/people/me?access_token={}".
            format(session.get("access_token")))
Exemplo n.º 6
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request, flash
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from .misc import usercheck, createuser, displayname, donorcreate
from .Classes import Ask

google_auth = GoogleClient(
    client_id=("458432068336-tocrspcbepahlmm1ovugke6hq9mqoqdf"
               ".apps.googleusercontent.com"),
    client_secret="HuUgIShcFgfT4P4YJ6IVKVKW",
    redirect_uri="http://*****:*****@app.route('/')
def index():
    complete = Ask.objects(complete=True)
    return render_template("index.html", Completed=complete)


@app.route('/login')
def login():
    if not session.get("access_token"):
        return redirect("/oauth2callback")
    with requests.Session() as s:
        s.auth = OAuth2BearerToken(session["access_token"])
        r = s.get(
            "https://www.googleapis.com/plus/v1/people/me?access_token={}".
Exemplo n.º 7
0
# Install dependencies with:
# pip install flask requests requests_oauth2
import os
import logging
import requests

from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from flask import Flask, request, redirect, session

app = Flask(__name__)
app.secret_key = os.environ.get("SECRET_KEY") or os.urandom(20)

google_auth = GoogleClient(
    client_id=("554229061086-np1qvffgq6gi1f6njg99qkeqt4h2gaut"
               ".apps.googleusercontent.com"),
    client_secret="XqTsoS6DXq-W0KgTqvQISBOM",
    redirect_uri="http://*****:*****@app.route("/")
def index():
    return redirect("/google/")


@app.route("/google/")
def google_index():
    if not session.get("access_token"):
        return redirect("/google/oauth2callback")
    with requests.Session() as s:
        s.auth = OAuth2BearerToken(session["access_token"])
Exemplo n.º 8
0
        return redirect(url_for('signin'))
    users.authenticated = True
    g.user = users
    login_user(users)
    Session['id'] = users.id
    A['user'] = True
    return render_template('index.html',
                           form=form,
                           register=register,
                           user=True)


# rauth OAuth 2.0 service wrapper
google_auth = GoogleClient(
    client_id=("client_id"
               ".apps.googleusercontent.com"),
    client_secret="secret",
    redirect_uri="http://*****:*****@app.route('/signin/signup_with_google')
def index():
    return redirect("/google/")


@app.route("/google/")
def google_index():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    if not session.get("access_token"):
        return redirect("/google/oauth2callback")
Exemplo n.º 9
0
# https://www.tutorialspoint.com/requests/requests_authentication.htm

# If server asks client for authentication information, e.g. username and password, for providing response/data:
# 1. client sends authentication information in the request headers when requesting a URL
# 2. server validate the information, i.e. required data will delivered if the authentication is valid

# OAuth2 authentication. You have to install OAuth2: 'pip install requests_oauth2'
import requests
from requests_oauth2.services import GoogleClient

google_auth = GoogleClient(client_id="xxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
   redirect_uri="http://localhost/auth/success.html")
a = google_auth.authorize_url(scope=["profile", "email"], response_type="code")
res = requests.get(a)
print(res.url)

# python -s Requests_Library\19_authentication_OAuth2.py
Exemplo n.º 10
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request, flash
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from .Classes import User, Transaction
from collections import Counter
import os

google_auth = GoogleClient(
    client_id=os.environ.get("GOOGLEAUTH_CLIENT_ID"),
    client_secret=os.environ.get("GOOGLEAUTH_CLIENT_SECRET"),
    redirect_uri="http://{}/oauth2callback".format(os.environ.get("URLHOST")))


@app.route('/', methods=['GET', 'POST'])
def index():
    ledgerTransactions = Transaction.objects.order_by('-createdate')

    # get totalmoney
    totalMoney = 0
    for transaction in ledgerTransactions:
        totalMoney += transaction.amount
    totalTransactions = len(list(Transaction.objects))

    # leaderboardUsers = list(User.objects.order_by('-reputation')[:9])
    leaderboardUsers = User.objects.order_by('-reputation')
    #get the categories that have been used
    #and how many transactions of that Category
    categoryList = Counter(
        [transaction.category for transaction in Transaction.objects])
Exemplo n.º 11
0
def create_app():
    app = Flask(__name__)
    app.secret_key = os.environ.get("SECRET_KEY") or os.urandom(20)

    google_auth = GoogleClient(
        client_id=("248542313858-cs7m96ilu4c4hckonl72c2n02teutmf6.apps.googleusercontent.com"),
        client_secret="k0Hl36IMGER0h9rRhZckEg7Q",
        redirect_uri="http://*****:*****@app.route("/")
    def index():
        return redirect("/logged-in/")

    @app.route("/donate")
    def donate():
        button = '<a href="https://link.justgiving.com/v1/charity/donate/charityId/189689?amount=5.00&currency=GBP&reference=be_nice&exitUrl=http%3A%2F%2Flocalhost%3A5000%2Fthanks%3FjgDonationId%3DJUSTGIVING-DONATION-ID&message=Its-good%20be%20be%20bad%20but%20being%20nice%20doesnt%20hurt%20either."><img src="https://vignette.wikia.nocookie.net/deep-space-69/images/9/99/Nice.png/revision/latest?cb=20130604210952" alt="Donate with JustGiving" /></a>'
        return f"text {button}"

    @app.route("/thanks")
    def thanks():
        gid = request.args.get('jgDonationId')
        print ("><><><><><><><><><><><><><")
        print (gid)
        return f"Donation Id Number: {gid}"

    @app.route("/logged-in/")
    def google_index():
        if not session.get("access_token"):
            return redirect("/google/oauth2callback")
        with requests.Session() as s:
            s.auth = OAuth2BearerToken(session["access_token"])
            r = s.get("https://www.googleapis.com/plus/v1/people/me")
        r.raise_for_status()
        data = r.json()
        name = data["displayName"]
        emails = data["emails"][0]["value"]

        try:
            gender = data["gender"],
        except Exception as e:
            gender = "not given",

        user = {"_id": data["id"],
                    "name": data["displayName"],
                    "email": data["emails"][0]["value"],
                    "gender": gender,
                    "date": datetime.now()
                }
        try:
            collection.insert_one(user)
        except Exception as e:
            error = str(e)

        # collection.delete_one({"_id":"106892412375491885318"})

        users = [element for element in collection.find()]
        # users = list(collection.find())


        niceUsers = json2html.convert(json = users)
        niceData = json2html.convert(json = data)

        print("><><><><><><><><><><")
        return f"Hello, {name}! Your email address is, {emails}<br/><br/>{niceData}<br/><br/><br/>{niceUsers}"


    @app.route("/google/oauth2callback")
    def google_oauth2callback():
        code = request.args.get("code")
        error = request.args.get("error")
        if error:
            return "error :( {!r}".format(error)
        if not code:
            return redirect(google_auth.authorize_url(
                scope=["profile", "email"],
                response_type="code",
            ))
        data = google_auth.get_token(
            code=code,
            grant_type="authorization_code",
        )
        session["access_token"] = data.get("access_token")


        return redirect("/")

    # Experimental route - seeing if we can use oAuth with JustGiving
    @app.route("/jg/")
    def jg_index():
        if not session.get("access_token"):
            return "not logged in"
        with requests.Session() as s:
            s.auth = OAuth2BearerToken(session["access_token"])
            r = s.get("http://api.justgiving.com/v1/account/getconsumerdetails")
        r.raise_for_status()
        data = r.json()

        return data


    return app
Exemplo n.º 12
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request, flash
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from app.Data import User, Transaction
from datetime import datetime

google_auth = GoogleClient(
    client_id=("1048349222266-n5praijtbm6a7buc893avtvmtr0k301p"
               ".apps.googleusercontent.com"),
    client_secret="gAarFeNq1vKtGXaxo96FS5H0",
    # redirect_uri="http://*****:*****@app.route('/login')
def login():
    if not session.get("access_token"):
        return redirect("/oauth2callback")
    with requests.Session() as s:
        s.auth = OAuth2BearerToken(session["access_token"])
        r = s.get(
            "https://www.googleapis.com/plus/v1/people/me?access_token={}".
            format(session.get("access_token")))
    r.raise_for_status()

    data = r.json()
Exemplo n.º 13
0
# matches the @app.route the it runs the function defined below it.

from app import app
from flask import render_template, redirect, url_for, session, request
from app.Data import Section, Assignment
from app.Data.User import User
from app.Forms import *
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
import requests
from flask import Flask, flash, redirect, render_template, request, url_for

google_auth = GoogleClient(
    client_id=("458432068336-tocrspcbepahlmm1ovugke6hq9mqoqdf"
               ".apps.googleusercontent.com"),
    client_secret="HuUgIShcFgfT4P4YJ6IVKVKW",
    redirect_uri="http://*****:*****@app.route('/', methods=['GET', 'POST'])
def index():
    return render_template("index.html")


# This tells the app what to do if the use requests the classes page --> http://127.0.0.1:5000/classes
# It will request all of the classes from the data object and then send them to the template
# "Section.objects.order_by('+period')" is the critical code.  First it makes a call to the
# Secion class in the Data folder which creates (instantiates) a new object that is sorted by
Exemplo n.º 14
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from .Classes import User, Transaction
from collections import Counter

google_auth = GoogleClient(
    client_id=("570439607080-1jbsss0dpsh9uf2ho0ng4vg999ioq38d"
               ".apps.googleusercontent.com"),
    client_secret="74a6PgTOympeG-WNgrOctcD7",
    redirect_uri="http://*****:*****@app.route('/', methods=['GET', 'POST'])
def index():
    ledgerTransactions = list(Transaction.objects[:9])[::-1]

    # get totalmoney
    totalMoney = 0
    for transaction in list(Transaction.objects):
        totalMoney += int(transaction.amount)
    totalTransactions = len(list(Transaction.objects))

    leaderboardUsers = list(User.objects.order_by('-reputation')[:9])

    #get the categories that have been used
Exemplo n.º 15
0
import requests
from app.routes import app
from flask import render_template, session, redirect, request
from requests_oauth2.services import GoogleClient
from requests_oauth2 import OAuth2BearerToken
from .Forms import SearchForm
from .misc import searchteachers, searchcourses, searchroom
from random import randint

google_auth = GoogleClient(
    client_id=("463567652450-0qq4vfd8kj1to717s7vs9clgesakg3pt"
               ".apps.googleusercontent.com"),
    client_secret="TNW6NLUPmF9wLCVIln7D0GqM",
    redirect_uri="https://otcoursecatalog.appspot.com/oauth2callback"
    # "http://*****:*****@app.route('/', methods=['GET', 'POST'])
def index():
    form = SearchForm(request.form)
    results = None
    results = None

    searchterm = ''
    searchby = 'teacher'

    if form.validate() and request.method == "POST":
        searchterm = form.searchterm.data
        form.searchterm.data = ''