Exemple #1
0
def test_blueprint_factory():
    digitalocean_bp = make_digitalocean_blueprint(client_id="foobar",
                                                  client_secret="supersecret")
    assert isinstance(digitalocean_bp, OAuth2ConsumerBlueprint)
    assert digitalocean_bp.session.client_id == "foobar"
    assert digitalocean_bp.client_secret == "supersecret"
    assert digitalocean_bp.token_url == "https://cloud.digitalocean.com/v1/oauth/token"
    assert (digitalocean_bp.authorization_url ==
            "https://cloud.digitalocean.com/v1/oauth/authorize")
Exemple #2
0
def test_scope_list_is_converted_to_space_delimited():
    digitalocean_bp = make_digitalocean_blueprint(client_id="foobar",
                                                  client_secret="supersecret",
                                                  scope="read,write")
    assert digitalocean_bp.session.scope == "read write"
Exemple #3
0
 def _make_app(*args, **kwargs):
     app = Flask(__name__)
     app.secret_key = "whatever"
     blueprint = make_digitalocean_blueprint(*args, **kwargs)
     app.register_blueprint(blueprint)
     return app
Exemple #4
0
def test_scope_list_is_valid_with_single_scope():
    digitalocean_bp = make_digitalocean_blueprint(client_id="foobar",
                                                  client_secret="supersecret",
                                                  scope="read")
    assert digitalocean_bp.session.scope == "read"
import os
import requests
from flask import Flask, request, render_template, redirect, url_for, session
from flask_dance.contrib.digitalocean import (make_digitalocean_blueprint,
                                              digitalocean)

app = Flask(__name__)
app.secret_key = os.environ.get("SECRET_KEY",
                                "bd042ab3623ccee8791da7aae39e9fbf")
app.config["DIGITALOCEAN_OAUTH_CLIENT_ID"] = os.environ.get(
    "DIGITALOCEAN_OAUTH_CLIENT_ID")
app.config["DIGITALOCEAN_OAUTH_CLIENT_SECRET"] = os.environ.get(
    "DIGITALOCEAN_OAUTH_CLIENT_SECRET")

digitalocean_bp = make_digitalocean_blueprint(scope="read,write")
app.register_blueprint(digitalocean_bp, url_prefix="/")


@app.route('/', methods=['GET'])
def index():
    if digitalocean.authorized:
        return redirect(url_for("droplets"))
    error = request.args.get('error', None)

    return render_template('index.html',
                           oauth_url=url_for("digitalocean.login"),
                           error=error)


@app.route('/droplets', methods=['GET'])
def droplets():