|
59 | 59 | from fence.utils import (
|
60 | 60 | get_valid_expiration,
|
61 | 61 | generate_client_credentials,
|
62 |
| - get_SQLAlchemyDriver, logger, |
| 62 | + get_SQLAlchemyDriver, logger, create_client, |
63 | 63 | )
|
64 | 64 | from sqlalchemy.orm.attributes import flag_modified
|
65 | 65 | from gen3authz.client.arborist.client import ArboristClient
|
@@ -1823,69 +1823,3 @@ def access_token_polling_job(
|
1823 | 1823 | with driver.session as db_session:
|
1824 | 1824 | loop = asyncio.get_event_loop()
|
1825 | 1825 | loop.run_until_complete(job.update_tokens(db_session))
|
1826 |
| - |
1827 |
| - |
1828 |
| -def create_client( |
1829 |
| - DB, |
1830 |
| - username=None, |
1831 |
| - urls=[], |
1832 |
| - name="", |
1833 |
| - description="", |
1834 |
| - auto_approve=False, |
1835 |
| - is_admin=False, |
1836 |
| - grant_types=None, |
1837 |
| - confidential=True, |
1838 |
| - arborist=None, |
1839 |
| - policies=None, |
1840 |
| - allowed_scopes=None, |
1841 |
| - expires_in=None, |
1842 |
| -): |
1843 |
| - client_id, client_secret, hashed_secret = generate_client_credentials(confidential) |
1844 |
| - if arborist is not None: |
1845 |
| - arborist.create_client(client_id, policies) |
1846 |
| - driver = get_SQLAlchemyDriver(DB) |
1847 |
| - auth_method = "client_secret_basic" if confidential else "none" |
1848 |
| - |
1849 |
| - allowed_scopes = allowed_scopes or config["CLIENT_ALLOWED_SCOPES"] |
1850 |
| - if not set(allowed_scopes).issubset(set(config["CLIENT_ALLOWED_SCOPES"])): |
1851 |
| - raise ValueError( |
1852 |
| - "Each allowed scope must be one of: {}".format( |
1853 |
| - config["CLIENT_ALLOWED_SCOPES"] |
1854 |
| - ) |
1855 |
| - ) |
1856 |
| - |
1857 |
| - if "openid" not in allowed_scopes: |
1858 |
| - allowed_scopes.append("openid") |
1859 |
| - logger.warning('Adding required "openid" scope to list of allowed scopes.') |
1860 |
| - |
1861 |
| - with driver.session as s: |
1862 |
| - user = None |
1863 |
| - if username: |
1864 |
| - user = query_for_user(session=s, username=username) |
1865 |
| - if not user: |
1866 |
| - user = User(username=username, is_admin=is_admin) |
1867 |
| - s.add(user) |
1868 |
| - |
1869 |
| - if s.query(Client).filter(Client.name == name).first(): |
1870 |
| - if arborist is not None: |
1871 |
| - arborist.delete_client(client_id) |
1872 |
| - raise Exception("client {} already exists".format(name)) |
1873 |
| - |
1874 |
| - client = Client( |
1875 |
| - client_id=client_id, |
1876 |
| - client_secret=hashed_secret, |
1877 |
| - user=user, |
1878 |
| - redirect_uris=urls, |
1879 |
| - allowed_scopes=" ".join(allowed_scopes), |
1880 |
| - description=description, |
1881 |
| - name=name, |
1882 |
| - auto_approve=auto_approve, |
1883 |
| - grant_types=grant_types, |
1884 |
| - is_confidential=confidential, |
1885 |
| - token_endpoint_auth_method=auth_method, |
1886 |
| - expires_in=expires_in, |
1887 |
| - ) |
1888 |
| - s.add(client) |
1889 |
| - s.commit() |
1890 |
| - |
1891 |
| - return client_id, client_secret |
0 commit comments