Skip to content

Commit

Permalink
add scopes and secret to device client example (#150)
Browse files Browse the repository at this point in the history
* add scopes and secret

* <bot> update dependencies*.log files(s)

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
dsschult and github-actions authored Aug 15, 2024
1 parent a49487e commit 669ea3d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dependencies-dev.log
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ requests-futures==1.0.1
# via wipac-rest-tools (setup.py)
requests-mock==1.12.1
# via wipac-rest-tools (setup.py)
ruff==0.5.7
ruff==0.6.0
# via wipac-rest-tools (setup.py)
tornado==6.4.1
# via wipac-rest-tools (setup.py)
Expand Down
6 changes: 3 additions & 3 deletions dependencies-mypy.log
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mypy==1.11.1
# via wipac-rest-tools (setup.py)
mypy-extensions==1.0.0
# via mypy
openapi-core==0.19.2
openapi-core==0.19.3
# via wipac-rest-tools (setup.py)
openapi-schema-validator==0.6.2
# via
Expand Down Expand Up @@ -193,7 +193,7 @@ rpds-py==0.20.0
# via
# jsonschema
# referencing
ruff==0.5.7
ruff==0.6.0
# via wipac-rest-tools (setup.py)
shellingham==1.5.4
# via click-completion
Expand Down Expand Up @@ -233,5 +233,5 @@ wipac-telemetry==0.3.0
# via wipac-rest-tools (setup.py)
wrapt==1.16.0
# via deprecated
zipp==3.19.2
zipp==3.20.0
# via importlib-metadata
2 changes: 1 addition & 1 deletion dependencies-openapi.log
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ markupsafe==2.1.5
# via werkzeug
more-itertools==10.4.0
# via openapi-core
openapi-core==0.19.2
openapi-core==0.19.3
# via wipac-rest-tools (setup.py)
openapi-schema-validator==0.6.2
# via
Expand Down
2 changes: 1 addition & 1 deletion dependencies-telemetry.log
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ wipac-telemetry==0.3.0
# via wipac-rest-tools (setup.py)
wrapt==1.16.0
# via deprecated
zipp==3.19.2
zipp==3.20.0
# via importlib-metadata
2 changes: 1 addition & 1 deletion dependencies-tests.log
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ requests-futures==1.0.1
# via wipac-rest-tools (setup.py)
requests-mock==1.12.1
# via wipac-rest-tools (setup.py)
ruff==0.5.7
ruff==0.6.0
# via wipac-rest-tools (setup.py)
shellingham==1.5.4
# via click-completion
Expand Down
21 changes: 17 additions & 4 deletions examples/get_device_credentials_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@
from rest_tools.client import SavedDeviceGrantAuth


def get_token(address, client_id):
rest_client = SavedDeviceGrantAuth('', token_url=address, filename='device-refresh-token', client_id=client_id)
def get_token(address, client_id, client_secret=None, scope=None):
scopes = scope if scope else []
rest_client = SavedDeviceGrantAuth(
address='',
token_url=address,
filename='device-refresh-token',
client_id=client_id,
client_secret=client_secret,
scopes=scopes,
)
# could use `rest_client` as a `RestClient`, but we're only interested in the token
return rest_client._openid_token()


def main():
parser = argparse.ArgumentParser(description='Get an OAuth2 token via client credentials')
parser.add_argument('--address', default='https://keycloak.icecube.wisc.edu/auth/realms/IceCube', help='OAuth2 server address')
parser.add_argument('--client_secret', default=None, help='client secret')
parser.add_argument('--scope', action='append', help='optional scopes')
parser.add_argument('--log-level', default='info', help='logging level')
parser.add_argument('client_id', help='client id')

logging.basicConfig(level=logging.DEBUG)

args = parser.parse_args()
kwargs = vars(args)

level = kwargs.pop('log_level').upper()
logging.basicConfig(level=getattr(logging, level))

print('access token:', get_token(**kwargs))


Expand Down

0 comments on commit 669ea3d

Please sign in to comment.