In an OAuthV2 Policy, I am trying to set an Attribute with a value from an ExtractVariable and cannot seem to get it working...
Here is the ExtractVariable policy. I confirmed via tracing that the variable is being set correctly.
<ExtractVariables name="extract-my-variables" continueOnError="false" enabled="true"> <DisplayName>ExtractMyVariables</DisplayName> <JSONPayload> <Variable name="useraccessid"> <JSONPath>$.UserAccessId</JSONPath> </Variable> </JSONPayload> <Source>calloutResponse</Source> </ExtractVariables>
and here is the OAuthV2 GenerateAccessToken Policy. I have narrowed down the issue to being ref="{useraccessid}". It doesn't appear to recognize the {useraccessid} ExtractVariable...
<OAuthV2 name="generate-access-token" continueOnError="false" enabled="true"> <DisplayName>GenerateAccessToken</DisplayName> <ExternalAuthorization>false</ExternalAuthorization> <Operation>GenerateAccessToken</Operation> <ExpiresIn>3600000</ExpiresIn> <RefreshTokenExpiresIn>86400000</RefreshTokenExpiresIn> <SupportedGrantTypes> <GrantType>password</GrantType> </SupportedGrantTypes> <Attributes> <Attribute name="useraccessid" ref="{useraccessid}" display="false"/> </Attributes> <GrantType>request.queryparam.grant_type</GrantType> <GenerateResponse enabled="true"/> </OAuthV2>
and here is the flow...
<Flow name="AccessToken"> <Description/> <Request> <Step> <Name>authenticate-user</Name> <Condition>request.queryparam.grant_type = "password"</Condition> </Step> <Step> <Name>extract-my-variables</Name> </Step> <Step> <Name>generate-access-token</Name> </Step> </Request> <Response/> <Condition>(proxy.pathsuffix MatchesPath "/accesstoken") and (request.verb = "POST")</Condition> </Flow>
Any assistance would be appreciated...
Solved! Go to Solution.
Hi @Anthony Coelho,
You don't need the { } around the variable in the policy. Here's an example of a policy that I know works that sets a custom attribute:
<OAuthV2 async="false" continueOnError="false" enabled="true" name="GenerateToken"> <DisplayName>GenerateToken</DisplayName> <Attributes> <Attribute display="true" name="USER_UUID" ref="streetcarts.user.id"/> <!-- Store the BaaS auth token here so it can be sent back for subsequent requests from the same user. --> <Attribute display="true" name="USER_BAAS_TOKEN" ref="streetcarts.user.baas.token"/> </Attributes> <ExpiresIn>-1</ExpiresIn> <ExternalAuthorization>false</ExternalAuthorization> <Operation>GenerateAccessToken</Operation> <GenerateResponse enabled="true"/> <ReuseRefreshToken>false</ReuseRefreshToken> <!-- Set the scope value from the variable value created in SetScope.js. --> <Scope>streetcarts.user.scope</Scope> <SupportedGrantTypes> <GrantType>password</GrantType> </SupportedGrantTypes> <Tokens/> </OAuthV2>
Hi @Anthony Coelho,
You don't need the { } around the variable in the policy. Here's an example of a policy that I know works that sets a custom attribute:
<OAuthV2 async="false" continueOnError="false" enabled="true" name="GenerateToken"> <DisplayName>GenerateToken</DisplayName> <Attributes> <Attribute display="true" name="USER_UUID" ref="streetcarts.user.id"/> <!-- Store the BaaS auth token here so it can be sent back for subsequent requests from the same user. --> <Attribute display="true" name="USER_BAAS_TOKEN" ref="streetcarts.user.baas.token"/> </Attributes> <ExpiresIn>-1</ExpiresIn> <ExternalAuthorization>false</ExternalAuthorization> <Operation>GenerateAccessToken</Operation> <GenerateResponse enabled="true"/> <ReuseRefreshToken>false</ReuseRefreshToken> <!-- Set the scope value from the variable value created in SetScope.js. --> <Scope>streetcarts.user.scope</Scope> <SupportedGrantTypes> <GrantType>password</GrantType> </SupportedGrantTypes> <Tokens/> </OAuthV2>
Thanks @wwitman. That was it! Thanks for the quick reply...
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |