sso/bin/application_add.py

55 lines
1.4 KiB
Python
Raw Normal View History

2017-10-09 20:01:37 +00:00
import random
import string
2020-02-24 18:46:38 +00:00
from website.app import create_app
from website.models import Client, db
app = create_app()
app.app_context().push()
2017-10-09 20:01:37 +00:00
app_name = ""
app_description = ""
client_id = ""
confidential = ""
redirect_uris = ""
while not app_name:
2020-02-24 18:46:38 +00:00
app_name = input("Application name (ie. Printmaster): ").strip()
2017-10-09 20:01:37 +00:00
while not app_description:
2020-02-24 18:46:38 +00:00
app_description = input("Application description (ie. Print control software): ").strip()
2017-10-09 20:01:37 +00:00
while not client_id:
2020-02-24 18:46:38 +00:00
client_id = input("OAuth Client ID (ie. printmaster): ").strip()
2017-10-09 20:01:37 +00:00
while not confidential:
2020-02-24 18:46:38 +00:00
confidential = input("Is the client confidential? Say yes for web apps, no for mobile apps: [yn] ").strip()
2017-10-09 20:01:37 +00:00
while not redirect_uris:
2020-02-24 18:46:38 +00:00
redirect_uris = input("Whitespace-delimited redirect URIs: ").strip()
2017-10-09 20:01:37 +00:00
if confidential.lower().startswith('y'):
confidential = True
else:
confidential = False
2020-02-24 18:46:38 +00:00
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)
2017-10-09 20:01:37 +00:00
2020-02-24 18:46:38 +00:00
while input("Type YES to continue. ") != "YES":
2017-10-09 20:01:37 +00:00
pass
c = Client()
c.name = app_name
c.description = app_description
c.client_id = client_id
2020-02-24 18:46:38 +00:00
c.client_secret = ''.join([random.choice("0123456789abcdef") for _ in range(32)])
2017-10-09 20:01:37 +00:00
c.is_confidential = confidential
c.redirect_uris_ = redirect_uris
db.session.add(c)
db.session.commit()
2020-02-24 18:46:38 +00:00
print("Client secret:", c.client_secret)