Hard code user credentials before calling the target endpoint

Hello All,

I am new to apigee, please pardon my ignorance My target endpoint requires username/password, so I wanted to hardcode the credentials, for this I created first a "KVM" .. Then I created the "Basic Authentication policy.. But when I use it I get following error

{
fault: {
faultstring: "Unresolved variable : CRAuthMap.cr.username",
detail: {
errorcode: "steps.basicauthentication.UnresolvedVariable"
}
}
}

Following is my KVM

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="CreateCRAuthMap">
    <DisplayName>CreateCRAuthMap</DisplayName>
    <Properties/>
    <ExpiryTimeInSecs>86400</ExpiryTimeInSecs>
    <Put>
        <Key>
            <Parameter>cr_username</Parameter>
        </Key>
        <Value>content-repo-reader</Value>
    </Put>
    <Put>
        <Key>
            <Parameter>cr_password</Parameter>
        </Key>
        <Value>XXXXXXX</Value>
    </Put>
    <Scope>environment</Scope>
</KeyValueMapOperations>

Following is my auth policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BasicAuthentication async="false" continueOnError="false" enabled="true" name="Basic-Authentication-1">
    <DisplayName>CR Authentication</DisplayName>
    <Operation>Encode</Operation>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <User ref="CRAuthMap.cr.username"/>
    <Password ref="CRAuthMap.cr.password"/>
    <AssignTo createNew="false">request.header.Authorization</AssignTo>
    <Source>request.header.Authorization</Source>
</BasicAuthentication>

Did i get this all wrong ..
Solved Solved
0 4 1,067
1 ACCEPTED SOLUTION

HI @Ravindra Mamidipaka

Welcome to the community !!

There was a similar post - please refer to this answer and let us know if you are still stuck

View solution in original post

4 REPLIES 4

HI @Ravindra Mamidipaka

Welcome to the community !!

There was a similar post - please refer to this answer and let us know if you are still stuck

Thank you, butI followed the same steps and I get

{
fault: {
faultstring: "Unresolved variable : cr.username",
detail: {
errorcode: "steps.basicauthentication.UnresolvedVariable"
}
}
}

following is my KVM policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="CR-Get-User-Crendentials" mapIdentifier="CRCredentials">
    <DisplayName>CR-Get-User-Crendentials</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
    <Get assignTo="cr.username" index="1">
        <Key>
            <Parameter>username</Parameter>
        </Key>
    </Get>
    <Get assignTo="cr.password" index="1">
        <Key>
            <Parameter>password</Parameter>
        </Key>
    </Get>
    <Scope>environment</Scope>
</KeyValueMapOperations>

Auth policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BasicAuthentication async="false" continueOnError="false" enabled="true" name="CR-Authentication">
    <DisplayName>CR Authentication</DisplayName>
    <Operation>Encode</Operation>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <User ref="cr.username"/>
    <Password ref="cr.password"/>
    <AssignTo createNew="false">request.header.Authorization</AssignTo>
    <Source>request.header.Authorization</Source>
</BasicAuthentication>

I added these policies to the "PreFlow" of the TargetEndpoints

@Ravindra Mamidipaka -

  1. Please double check if you created the KVM on the same environment where you have deployed this proxy. For example, if you have deployed this proxy to "test" environment, make sure that the KVM you created - "CRCredentials" is also under test
  2. If the KVM is encrypted, you need to prefix the variable with "private." - so in your case it will be "private.cr.username" and "private.cr.password"
  3. Also use the new variables in the Basic Auth policy.
  4. Make sure KVM policy is called first followed by Basic Auth policy and both of these are placed in the request flow of TargetEndpoint or ProxyEndpoint

KVM policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="CR-Get-User-Crendentials" mapIdentifier="CRCredentials">
    <DisplayName>CR-Get-User-Crendentials</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
    <Get assignTo="private.cr.username" index="1">
        <Key>
            <Parameter>username</Parameter>
        </Key>
    </Get>
    <Get assignTo="private.cr.password" index="1">
        <Key>
            <Parameter>password</Parameter>
        </Key>
    </Get>
    <Scope>environment</Scope>
</KeyValueMapOperations>

Basic Auth policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BasicAuthentication async="false" continueOnError="false" enabled="true" name="CR-Authentication">
    <DisplayName>CR Authentication</DisplayName>
    <Operation>Encode</Operation>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <User ref="private.cr.username"/>
    <Password ref="private.cr.password"/>
    <AssignTo createNew="false">request.header.Authorization</AssignTo>
</BasicAuthentication>

Yup that is the issue. my creds are encoded and I did not add the "private". Thanks for the hep.