How to set dynamic value to expires_in field in oauth token?

I am validating a saml token using thumbprint and want to set the expiry value of oauth token as per the saml token that is being validated.

I was able to get the value in seconds, but the oauth policy is not accepting the vaiable in the expires_in field.

I tried to pass the variable in the below ways.

saml_sessionLength

saml_sessionLength

{saml_sessionLength}

Error :

Error creating object

Error occurred while validation of bean OA_GenerateAccessTokenSAML.xml. Reason: - Schema validation failed. Cause : For input string: ‘’. Line number : 8. Column number : 14. File name : OA_GenerateAccessTokenSAML.xml..

1 Like

Hi @Pranay Aitha

According to docs http://docs.apigee.com/api-services/content/oauthv2-policy#expiresinelement

I can see the expires_in can be set using a flow variable.

only thing that seems to be missing from above is the default value from the sntax.

Can you put in that and try?

{default_value}

I did not try it on my side though

1 Like

The expiry time can also be set at runtime using a reference to a flow variable or it can be hard-coded.

E.g. In the below configuration, expiresIn is set from with the value specified in the query param “expires_in”. If this value is not specified then it’s set as 1000 milli seconds by default.

<ExpiresIn ref="request.queryparam.expires_in">1000</ExpiresIn>

Please note that the flow variable value takes precedence over the specified default value.

@Pranay Aitha ,

Seems like error is due to some other reason. Do you still see this issue ?

The trap is even if the variable is null the defautl value is not taken in account .

The best way is to set the variable before the token generation…

getting this error “java.lang.Long cannot be cast to java.lang.String” when trying to set expires_in from a flow variable.

360000000

Just make the value a smaller one instead of so big. Try as 3600000

1 Like

This works if we set the type for extract variable.