Difficulties understanding custom authorizer example #507
-
Hi everyone, We are implementing a custom authorizer and would like to better understand the parameters needed for token validation as the documentation is not very clear. I read the tutorial here and I'm on Step 4: Test the authorizer by calling test-invoke-authorizer It's a shame that in this example the AWS CLI is used as this does not align with e.g. I'm stuck on the authorizerName: "<Name of your custom authorizer>",
username: "<Value of the username field that should be passed to the authorizer's lambda>",
password: <Binary data value of the password field to be passed to the authorizer lambda>,
tokenKeyName: "<Name of the username query param that will contain the token value>",
tokenValue: "<Value of the username query param that holds the token value that has been signed>",
tokenSignature: "<base64-encoded digital signature of tokenValue>" In the following example from the tutorial, I assume the aws iot test-invoke-authorizer \
--authorizer-name my-new-authorizer \
--token tokenKeyValue \
--token-signature dBwykzlb+fo+JmSGdwo The code gives a bit more detail, but some developers may not find this immediately. /**
* Configuration options specific to
* [AWS IoT Core custom authentication](https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html)
* features. For clients constructed by an {@link AwsIotMqtt5ClientConfigBuilder}, all parameters associated
* with AWS IoT custom authentication are passed via the username and password properties in the CONNECT packet.
*/
export interface MqttConnectCustomAuthConfig {
/**
* Name of the custom authorizer to use.
*
* Required if the endpoint does not have a default custom authorizer associated with it. It is strongly suggested
* to URL-encode this value; the SDK will not do so for you.
*/
authorizerName?: string;
/**
* The username to use with the custom authorizer. Query-string elements of this property value will be unioned
* with the query-string elements implied by other properties in this object.
*
* For example, if you set this to:
*
* 'MyUsername?someKey=someValue'
*
* and use {@link authorizerName} to specify the authorizer, the final username would look like:
*
* `MyUsername?someKey=someValue&x-amz-customauthorizer-name=<your authorizer's name>&...`
*/
username?: string;
/**
* The password to use with the custom authorizer. Becomes the MQTT5 CONNECT packet's password property.
* AWS IoT Core will base64 encode this binary data before passing it to the authorizer's lambda function.
*/
password?: mqtt5_packet.BinaryData;
/**
* Key used to extract the custom authorizer token from MQTT username query-string properties.
*
* Required if the custom authorizer has signing enabled. It is strongly suggested to URL-encode this value; the
* SDK will not do so for you.
*/
tokenKeyName?: string;
/**
* An opaque token value. This value must be signed by the private key associated with the custom authorizer and
* the result placed in the {@link tokenSignature} property.
*
* Required if the custom authorizer has signing enabled.
*/
tokenValue?: string;
/**
* The digital signature of the token value in the {@link tokenValue} property. The signature must be based on
* the private key associated with the custom authorizer. The signature must be base64 encoded.
*
* Required if the custom authorizer has signing enabled.
*/
tokenSignature?: string;
} What we are trying to achieve is leveraging the already existing |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
If I use the existing JWT const jwt =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.NFvYpuwbF6YWbPyaNAGEPw9wbhiQSovvSrD89B8K7Ng";
const jwtParts = jwt.split(".");
const jwtHeader = jwtParts[0];
const jwtPayload = jwtParts[1];
const jwtSignature = jwtParts[2];
const mqttConnectCustomAuthConfig = {
tokenKeyName: "t",
tokenValue: `${jwtHeader}.${jwtPayload}`,
tokenSignature: jwtSignature,
};
console.log(mqttConnectCustomAuthConfig);
// {
// tokenKeyName: 't',
// tokenValue: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ',
// tokenSignature: 'NFvYpuwbF6YWbPyaNAGEPw9wbhiQSovvSrD89B8K7Ng'
// } |
Beta Was this translation helpful? Give feedback.
-
I'll try to walk through a basic example and hopefully that will make things clearer (square brackets denotes substitution). You want to make a signed custom authorizer. Start with a key pair: Create a signing custom authorizer. Ignoring Lambda configuration, a signed custom authorizer is configured with the public key and the
Choose a value for With that, configure the SDK custom auth parameters as follows:
This leads to the SDK building a final username field for the CONNECT packet that looks like this:
After this, you may find yourself asking "Why does One other thing. I'm not certain, but it does seem like you might be conflating two completely unrelated notions of |
Beta Was this translation helpful? Give feedback.
I'll try to walk through a basic example and hopefully that will make things clearer (square brackets denotes substitution).
You want to make a signed custom authorizer.
Start with a key pair:
(PubKey, PrivKey)
Create a signing custom authorizer. Ignoring Lambda configuration, a signed custom authorizer is configured with the public key and the
token-key-name
value.token-key-name
is the name of the query parameter that you (well, the SDK) will stick the unsigned token value in . In other words, the custom authorizer service expects the query param pair[token-key-name]=[unsigned-token-value]
to appear in the username field of the CONNECT packet whenever you try to connect[My-Authorizer-…