Double login (steem/hive) for website

in #steem4 years ago

d.png

I was doing some research few days ago, about the possibility to login both with steemlogin and hivesigner, on the same website, and I noticed there is no website that actually offer this service, or maybe I just miss it.

In any case I tried to develop a basic method to allow users to chose between steemlogin or hivesigner, to login.

To do so I used flask, so python language and the hivesigner package and the steemlogin I just forked from the first one.

Actually was quite easy and it worked quite fast.

So let's import the package for this:

from hivesigner.client import Client
from steemlogin.client import Client_sl [I changed it to differenciate from hivesigner Client]
import re
from flask import Flask, request, render_template,render_template_string, flash, redirect, url_for,send_from_directory,session

than declare the app name we set up before on both blockchains and create the objects for steem and hive:

client_id = "[app name]"
client_secret="[secret app key]"
ch = Client(client_id=client_id, client_secret=client_secret)
cs = Client_sl(client_id=client_id, client_secret=client_secret)

Than very esay, let's redirect the users to 2 different pages based on if they chose steem or hive login method:

@app.route('/steem')
def steem():
    login_url_s = cs.get_login_url(
        "http://localhost:5000/steem",
        "login",
        )
    cs.access_token = request.args.get("access_token")
    try:
        login=cs.me()["name"]
        link='#'
    except Exception as e:
        login="Log In"
        link=login_url_s
    return render_template('home_in.html',login=login,color="#0BA0DC",ac=ac_img,power='STEEM POWER')    
####################################STEEM
########################################## HIVE
@app.route('/hive')
def hive():
    
    login_url_h = ch.get_login_url(
        "http://localhost:5000/hive",
        "login",
        )
    ch.access_token = request.args.get("access_token")
    try:
        login=ch.me()["name"]
        link='#'
    except Exception as e:
        login="Log In"
        link=login_url_h
    return render_template('home_in.html',login=login,color="#E71111",ac=ac_img,power='HIVE POWER')

With this very simple method you can have both steem and hive login with steemlogin and hivesigner on your website.

dm_or_piccolo.png

Coin Marketplace

STEEM 0.23
TRX 0.21
JST 0.035
BTC 97405.88
ETH 3349.98
USDT 1.00
SBD 3.18