def test_blueprint_factory(): linkedin_bp = make_linkedin_blueprint(client_id="foo", client_secret="bar", scope="user:email", redirect_to="index") assert isinstance(linkedin_bp, OAuth2ConsumerBlueprint) assert linkedin_bp.session.scope == "user:email" assert linkedin_bp.session.base_url == "https://api.linkedin.com/v2/" assert linkedin_bp.session.client_id == "foo" assert linkedin_bp.client_secret == "bar" assert (linkedin_bp.authorization_url == "https://www.linkedin.com/oauth/v2/authorization") assert linkedin_bp.token_url == "https://www.linkedin.com/oauth/v2/accessToken"
def test_blueprint_factory(): linkedin_bp = make_linkedin_blueprint( client_id="foo", client_secret="bar", scope="user:email", redirect_to="index" ) assert isinstance(linkedin_bp, OAuth2ConsumerBlueprint) assert linkedin_bp.session.scope == "user:email" assert linkedin_bp.session.base_url == "https://api.linkedin.com/v2/" assert linkedin_bp.session.client_id == "foo" assert linkedin_bp.client_secret == "bar" assert ( linkedin_bp.authorization_url == "https://www.linkedin.com/oauth/v2/authorization" ) assert linkedin_bp.token_url == "https://www.linkedin.com/oauth/v2/accessToken"
def _make_app(*args, **kwargs): app = Flask(__name__) app.secret_key = "whatever" blueprint = make_linkedin_blueprint(*args, **kwargs) app.register_blueprint(blueprint) return app
# Creating flask instance app = Flask(__name__) app.config.from_object(DevelopmentConfig) #Database instance db = MySQL(app) jwt = JWTManager(app) #handling environment variable os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1' #initiating instacnces for flask dance linkedin_blueprint = make_linkedin_blueprint( client_id=app.config['LINKEDIN_CLIENT_ID'], client_secret=app.config['LINKEDIN_CLIENT_SECRET'], scope='r_liteprofile,r_emailaddress', redirect_url='/login/linkedin') facebook_blueprint = make_facebook_blueprint( client_id=app.config['FACEBOOK_CLIENT_ID'], client_secret=app.config['FACEBOOK_CLIENT_SECRET'], redirect_url='/login/facebook') google_blueprint = make_google_blueprint( client_id=app.config['GOOGLE_CLIENT_ID'], client_secret=app.config['GOOGLE_CLIENT_SECRET'], redirect_url='/login/google', scope=["email", "profile"]) app.register_blueprint(linkedin_blueprint, url_prefix='/linkedin_login') app.register_blueprint(facebook_blueprint, url_prefix='/facebook_login') app.register_blueprint(google_blueprint, url_prefix='/google_login')
from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_dance.contrib.linkedin import make_linkedin_blueprint, linkedin app = Flask(__name__) app.config.from_pyfile('settings.py') # sql connection sqldb = SQLAlchemy(app) # ensure all tables migrate = Migrate(app, sqldb) # linkedin login linkedin_bp = make_linkedin_blueprint( scope=["r_liteprofile", "r_emailaddress"]) app.register_blueprint(linkedin_bp, url_prefix="/login") # repositories from .db.repository.UserRepository import UserRepository user_repository = UserRepository() # register the routes from .routes.routes import bp app.register_blueprint(bp) # import db models for migrations from .db import models import flask_whooshalchemy
from flask_dance.consumer import oauth_authorized from werkzeug.utils import secure_filename from sqlalchemy import func, distinct import os import uuid import shortuuid os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' UPLOAD_FOLDER = 'static/uploads' app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://SudoAdmin@interq:P@[email protected]:5432/postgres" app.config['SECRET_KEY'] = '0817PDNTSPA' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER linkedin_bp = make_linkedin_blueprint(scope=["r_liteprofile", "r_emailaddress"], client_id='78qzro4mo4fjas', client_secret='vFFSwRhq7bCII41S', redirect_to='dashboard') app.register_blueprint(linkedin_bp, url_prefix='/login') db.app = app db.init_app(app) db.create_all() login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = '/login' @login_manager.user_loader def load_user(user_id): return Users.query.get(user_id) @app.errorhandler(404)
import os from flask import Flask, redirect, url_for from flask_dance.contrib.linkedin import make_linkedin_blueprint, linkedin app = Flask(__name__) app.secret_key = os.environ.get("FLASK_SECRET_KEY", "supersekrit") app.config["LINKEDIN_OAUTH_CLIENT_ID"] = os.environ.get("LINKEDIN_OAUTH_CLIENT_ID") app.config["LINKEDIN_OAUTH_CLIENT_SECRET"] = os.environ.get( "LINKEDIN_OAUTH_CLIENT_SECRET" ) linkedin_bp = make_linkedin_blueprint(scope=["r_liteprofile"]) app.register_blueprint(linkedin_bp, url_prefix="/login") def preferred_locale_value(multi_locale_string): """ Extract the value of the preferred locale from a MultiLocaleString https://docs.microsoft.com/en-us/linkedin/shared/references/v2/object-types#multilocalestring """ preferred = multi_locale_string["preferredLocale"] locale = "{language}_{country}".format( language=preferred["language"], country=preferred["country"] ) return multi_locale_string["localized"][locale] @app.route("/") def index(): if not linkedin.authorized: return redirect(url_for("linkedin.login"))
app.config['SECRET_KEY']='verysecretnoonecanknowit' app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///db.sqlite3' app.config.update( MAIL_SERVER='smtp.gmail.com', MAIL_PORT=465, MAIL_USE_SSL=True, MAIL_USE_TLS=False, ) # for authentication by linkedin we need to make a blueprint which includes id and secret keys of using linkedin API blueprint = make_linkedin_blueprint( client_id="81tk3h8swqr0cw", client_secret="oZX4ksnP3igoZRvJ", scope=["r_liteprofile"], # scopes for what type of data we are accessing in this case profile ) # register app for blueprint , database and mail app.register_blueprint(blueprint,url_prefix="/linked_login") db=SQLAlchemy(app) mail=Mail(app) # classes we used in authentication user class have all information # is_admin is for checking that whether the user is admin or not (role based Authentication) class User(db.Model,UserMixin):