Add tool to create clients.
parent
b4a4a26a2f
commit
3f7b06129b
|
@ -0,0 +1,50 @@
|
|||
import random
|
||||
import string
|
||||
|
||||
from auth import app, Client, db
|
||||
|
||||
app_name = ""
|
||||
app_description = ""
|
||||
client_id = ""
|
||||
confidential = ""
|
||||
redirect_uris = ""
|
||||
|
||||
while not app_name:
|
||||
app_name = raw_input("Application name (ie. Printmaster): ").strip()
|
||||
while not app_description:
|
||||
app_description = raw_input("Application description (ie. Print control software): ").strip()
|
||||
while not client_id:
|
||||
client_id = raw_input("OAuth Client ID (ie. printmaster): ").strip()
|
||||
while not confidential:
|
||||
confidential = raw_input("Is the client confidential? Say yes for web apps, no for mobile apps: [yn] ").strip()
|
||||
while not redirect_uris:
|
||||
redirect_uris = raw_input("Whitespace-delimited redirect URIs: ").strip()
|
||||
|
||||
if confidential.lower().startswith('y'):
|
||||
confidential = True
|
||||
else:
|
||||
confidential = False
|
||||
|
||||
|
||||
print "\n\nSummary\n-------"
|
||||
print "Application name:", app_name
|
||||
print "Application description:", app_description
|
||||
print "Client ID:", client_id
|
||||
print "Confidential client:", confidential
|
||||
print "Redirect URIs:", redirect_uris
|
||||
|
||||
while raw_input("Type YES to continue. ") != "YES":
|
||||
pass
|
||||
|
||||
c = Client()
|
||||
c.name = app_name
|
||||
c.description = app_description
|
||||
c.client_id = client_id
|
||||
c.client_secret = ''.join([random.choice(string.uppercase + string.lowercase) for _ in range(32)])
|
||||
c.is_confidential = confidential
|
||||
c.redirect_uris_ = redirect_uris
|
||||
|
||||
db.session.add(c)
|
||||
db.session.commit()
|
||||
|
||||
print "Client secret:", c.client_secret
|
Reference in New Issue