Hi, i have a question about basic auth. I am not interested in actually validating credentials. I am interested in two things 1. getting the policies i created to actually work and 2. getting apigee management to encode the credentials passed. I am using apigee trial account.
So i followed apigee documentation and first created a key value map.
BasicAuthCredentials with username and password variables populated.
(i am skipping steps such as creating api apps, api products, etc).
Then i created policies for a specific api proxy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations name="getUsername" mapIdentifier="BasicAuthCredentials"> <Scope>apiproxy</Scope> <Get assignTo="credentials.username" index="1"> <Key> <Parameter ref="BasicAuth.credentials.username"/> </Key> </Get> </KeyValueMapOperations>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations name="getPassword" mapIdentifier="BasicAuthCredentials"> <Scope>apiproxy</Scope> <Get assignTo="credentials.password" index="1"> <Key> <Parameter ref="BasicAuth.credentials.password"/> </Key> </Get> </KeyValueMapOperations>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <BasicAuthentication async="false" continueOnError="false" enabled="true" name="Basic-Authentication-1"> <DisplayName>Basic Authentication-1</DisplayName> <Operation>Encode</Operation> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <User ref="BasicAuth.credentials.username"/> <Password ref="BasicAuth.credentials.password"/> <AssignTo createNew="false">request.header.Authorization</AssignTo> <Source>request.header.Authorization</Source> </BasicAuthentication>
Then i tested via the api console (while tracing within the api management gateway).
I select basic auth and then entered username and password as stored in key map.
i get the following error
HTTP/1.1 500 Internal Server Error
<code>{"fault":{"faultstring":"Unresolved variable : BasicAuth.credentials.username","detail":{"errorcode":"steps.basicauthentication.UnresolvedVariable"}}}
<code>can anyone help? <br>
,
So, i am trying to understand how to do basic authentication.. i am not trying to authenticate (which many people seem to assume when they answer this type of question).. i am merely trying to do the following 1. Encode the credentials. 2. get the policies to work!!!. I am using apigee edge trial account.
So i followed the example on apigee. in the dev environment, i created the key value map "BasicAuthCredentials" with a username and password.
Then in my proxy i create the following policies
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations name="getUsername" mapIdentifier="BasicAuthCredentials"> <Scope>apiproxy</Scope> <Get assignTo="credentials.username" index="1"> <Key> <Parameter ref="BasicAuth.credentials.username"/> </Key> </Get> </KeyValueMapOperations>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations name="getPassword" mapIdentifier="BasicAuthCredentials"> <Scope>apiproxy</Scope> <Get assignTo="credentials.password" index="1"> <Key> <Parameter ref="BasicAuth.credentials.password"/> </Key> </Get> </KeyValueMapOperations>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <BasicAuthentication async="false" continueOnError="false" enabled="true" name="Basic-Authentication-1"> <DisplayName>Basic Authentication-1</DisplayName> <Operation>Encode</Operation> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <User ref="BasicAuth.credentials.username"/> <Password ref="BasicAuth.credentials.password"/> <AssignTo createNew="false">request.header.Authorization</AssignTo> <Source>request.header.Authorization</Source> </BasicAuthentication>
Then i go to api console and before i execute, i select basic auth, which ask for username and password, which i supply (the values i created in key map).
I get this eror
HTTP/1.1 500 Internal Server ErrorDate:Tue, 08 Aug 2017 20:15:38 GMTContent-Length:150Connection:keep-aliveContent-Type:application/jsonServer:Apigee Router{"fault":{"faultstring":"Unresolved variable : BasicAuth.credentials.username","detail":{"errorcode":"steps.basicauthentication.UnresolvedVariable"}}}<br>
Hi,Could you please change the User and Password ref mention below , As you have already stored those values in other variable using KVM.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <BasicAuthenticationasync="false"continueOnError="false"enabled="true"name="Basic-Authentication-1"> <DisplayName>Basic Authentication-1</DisplayName> <Operation>Encode</Operation> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <Userref="credentials.username"/> <Passwordref="credentials.password"/> <AssignTocreateNew="false">request.header.Authorization</AssignTo> <Source>request.header.Authorization</Source> </BasicAuthentication>
Adding to what @Umanng Goel said , also have a look at the parameter names in the KVM policy. I see that you are using a reference to a flow variable BasicAuth.credentials.username.
I am assuming the key name in your KVM policy is BasicAuth.credentials.username & BasicAuth.credentials.password. If my assumption is correct then you have to use the kvm policy like this. Please remember ref attribute is supposed to be used only when you want the value of a flow variable to be used as key parameter name
<KeyValueMapOperations name="getUsername" mapIdentifier="BasicAuthCredentials"> <Scope>apiproxy</Scope> <Get assignTo="credentials.username" index="1"> <Key> <Parameter>BasicAuth.credentials.username</Parameter> </Key> </Get> <Get assignTo="credentials.password" index="1"> <Key> <Parameter>BasicAuth.credentials.password</Parameter> </Key> </Get> </KeyValueMapOperations>
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |