Skip to content

Commit

Permalink
Adjustment for multi-auth with OAuth.
Browse files Browse the repository at this point in the history
  • Loading branch information
depfeife-msft committed Jul 28, 2021
1 parent a8a10ed commit 345d3e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tools/paconn-cli/paconn/operations/json_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
_SCRIPT_URI = 'scriptDefinitionUrl'
_CONNECTION_PARAMETERS = 'connectionParameters'
_CONNECTION_PARAMETER_SET = 'connectionParameterSets'
_PARAMETERS = 'parameters'
_VALUES = 'values'

# Save
_API_DEFINITIONS = 'apiDefinitions'
Expand Down
16 changes: 15 additions & 1 deletion tools/paconn-cli/paconn/operations/upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
_BASE_PATH,
_DISPLAY_NAME,
_CONNECTION_PARAMETERS,
_CONNECTION_PARAMETER_SET,
_PARAMETERS,
_VALUES,
_TOKEN,
_OAUTH_SETTINGS,
_CLIENT_SECRET,
Expand Down Expand Up @@ -82,7 +85,7 @@ def upsert(powerapps_rp, settings, client_secret, is_update, overwrite_settings)
# Get the property object
properties = property_definition[_PROPERTIES]

# Add secret
# Add secret in connection parameter
token_property = properties.get(_CONNECTION_PARAMETERS, {}).get(_TOKEN, None)
if token_property:
oauth_settings = token_property.get(_OAUTH_SETTINGS, None)
Expand All @@ -91,6 +94,17 @@ def upsert(powerapps_rp, settings, client_secret, is_update, overwrite_settings)
elif oauth_settings and not client_secret and not is_update:
raise CLIError('Please provide OAuth2 client secret using the --secret argument.')

# Add secret in connection parameter set
multi_auth = properties.get(_CONNECTION_PARAMETER_SET, {}).get(_VALUES, [])
for auth in multi_auth:
token_property = auth.get(_PARAMETERS).get(_TOKEN)
if token_property:
oauth_settings = token_property.get(_OAUTH_SETTINGS, None)
if oauth_settings and client_secret:
oauth_settings[_CLIENT_SECRET] = client_secret
elif oauth_settings and not client_secret and not is_update:
raise CLIError('Please provide OAuth2 client secret using the --secret argument.')

# Load swagger definition
with open(settings.api_definition, 'r') as file:
openapi_definition = json.load(file)
Expand Down

0 comments on commit 345d3e6

Please sign in to comment.