I am attempting to stored detailed information about users in my AWS Cognito user pool. I can retrieve the standard attributes, such as name or username, just fine with user.attributes.phone_number, however attempting to to the same thing with user.attributes.custom:MyCustomAttribute simply yielded an error because of the colon. I have ensured that my custom attributes can be read from across all platforms.
I decided to inspect the return key to see where the custom attributes are supposed to be, to find this:
attributes: Object
email: (...)
email_verified: (...)
name: (...)
phone_number: (...)
phone_number_verified: (...)
sub: (...)
__ob__: Observer {value: {…}, dep: Dep, vmCount: 0}
get email: ƒ reactiveGetter()
set email: ƒ reactiveSetter(newVal)
get email_verified: ƒ reactiveGetter()
set email_verified: ƒ reactiveSetter(newVal)
get name: ƒ reactiveGetter()
set name: ƒ reactiveSetter(newVal)
get phone_number: ƒ reactiveGetter()
set phone_number: ƒ reactiveSetter(newVal)
get phone_number_verified: ƒ reactiveGetter()
set phone_number_verified: ƒ reactiveSetter(newVal)
get sub: ƒ reactiveGetter()
set sub: ƒ reactiveSetter(newVal)
__proto__: Object
Where/how am I supposed to be able to retrieve and edit my custom attributes and values? I've theorized that it may be in one of the tokens, but I don't have the experience to really act off of that. It seems that it may also not be showing because there is no data, but I need to know how to access them in the first place to change the data, leaving me in the same place.
Turns out that they are stored just fine, EXCEPT you cannot use dot notation to access them. Instead of:
user.attirbutes.custom:MyAttribute
You have to use:
user.attributes['custom:MyAttribute']
as per this GitHub discussion, where user annjawn says the above.
Related
I'm currently trying to make an API doc page thanks to nelmio-api-bundle. I only have one route which is a POST route. I'm receiving a JSON in the body of the request and I'm using the Serializer from symfony to deserialize it in a DTO. I'm also using a DTO for the response (which contains the status code, a bool set to true or false, and a message). Now I'm trying to use these DTO (for input and output) to build the API documentation with nelmio-api-bundle but how to make it ? I'm using PHP8.1 attributes to make it, for response it almost works (except that the response is shows as an array) but I don't know how to make it for the inputs.
Here is my current code:
#[Route('/user', methods: ['POST'])]
#[OA\Parameter(
name: 'user',
description: 'The user information in JSON',
in: 'query',
required: true
)]
#[OA\Response(
response: 200,
description: 'Returns the success response',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: new Model(type: SuccessResponseDTO::class))
)
)]
public function registerUser(Request $request, LoggerInterface $logger): JsonResponse
{
//the code to register the user
}
And here is the result:
Do someone know how to make it ?
I'm working on a test for a module, which works except for the fact that I can not access, the inner object attributes properties.
tokenStorageServiceStub = { // Mock service data
getUser: () => of({
username: 'organization-a-a-normal',
roles: ['PROCESSOR'],
attributes: {
organizationId: 111,
organizationName: 'Org.name Aa',
userFullName: 'User for organization A-A',
userId: 22,
},
access_token: 'AT01',
refresh_token: 'RT01',
token_type: 'Bearer',
expires_in: 3600,
}),
};
The component code complains about the last statement:
this.activeTokens = this.token.getUser(); // OK
this.username = this.activeTokens.username; // OK
this.organization.id = this.activeTokens.attributes.organizationId; // `attributes` is undefined?
Chrome Headless 88.0.4298.0 (Linux x86_64) SettingsComponent should create FAILED
TypeError: Cannot read property 'organizationId' of undefined
at SettingsComponent.call [as ngOnInit] (src/app/organization/settings/settings.component.ts:22:61)
I think it's because of the innerworking of the RxJs.of() function. In the manual, I see things like ObservableInput. But there is no mention of Objects as such.
I also read about of() getting deprecated? What will be a good approach to pass my object data in a test service stub?
I am working on providing a GET REST API where I would like to conditionally include the total_documents field (its an integer count of the total number of records present in the DB table).
The API signature and response payload will be something like:
GET /endpoint/?total_documents&.....
Response Payload:
{
documents: [....],
total_documents: 100
}
Now I would like the total_documents field to be appeared in the response payload if and only if the total_documents query parameter exists in the URL.
This is what I tried, based on my schema:
fastify.addSchema({
$id: 'persistence-query-params',
title: "PersistenceQueryParams",
type: 'object',
description: 'Persistence Service GET API URL query specification. Applicable for GET API only.',
properties: {
'total_documents': {
description: 'Total number of documents present in the collection, after applying filters, if any. This query paramater does not take any value, just pass it as the name (e.g. &total_documents).',
nullable: true,
},
},
}
querystring: {
description: 'Persistence Service GET API URL query specification. Applicable for GET API only.',
$ref: 'persistence-query-params#',
},
response: {
200: {
properties: {
'documents': {
description: 'All the retrieved document(s) from the specified collection for the specified service database and account.',
type: 'array',
items: {
$ref: 'persistence-response-doc#',
}
},
'total_documents': {
description: "If total_documents query paremeter is specified, gives the total number of documents present in the collection, after applying query paramaters, if any. If total_documents is not specified, this field will not be available in the response payload.",
type: 'number',
default: -1,
},
},
dependencies: {
'total_documents': { required: ['querystring/properties/total_documents'] },
},
},
'4xx': {
$ref: 'error-response#',
description: 'Error response.'
}
}
What is the way out here?
Thanks,
Pradip
JSON Schema has no notion of a request or response or HTTP.
What you have here is an OpenAPI specification document.
The OpenAPI specification defines a way to access dynamic values, but only within Link Objects or Callback Objects, which includes the query params.
Runtime expressions allow defining values based on information that
will only be available within the HTTP message in an actual API call.
This mechanism is used by Link Objects and Callback Objects.
https://spec.openapis.org/oas/v3.1.0#runtime-expressions
JSON Schem has no way to reference instance data, let alone data relating to contexts it is unaware of.
I tried to call the InitiateAuth API from AWS CLI. I have set up Define auth, create auth and verify auth lambda triggers correctly. The problem is that, when I ran the below command, it's showing error:
aws cognito-idp initiate-auth --client-id <my_client_id> --auth-flow CUSTOM_AUTH --auth-parameters USERNAME=uname,ChallengeName="SRP_A",SRP_A="<srp_value>"
Error: An error occurred (UserLambdaValidationException) when calling the InitiateAuth operation: DefineAuthChallenge failed with error Cannot read property 'challengeName' of undefined.
I checked the Define Auth lambda code, and also the Cloud Watch logs of Lambda execution. The error occurred because the input from Cognito contains an empty session key in the event json (which usually sent from Cognito to Lambda). As the property challengeName resides inside the session key (as shown in official documentation).
Here is the JSON event sent to Lambda from Cognito when I ran that command (I got this JSON from CloudWatch Lambda logs, I printed the event which is being sent from Cognito):
{
version: '1',
region: 'us-east-1',
userPoolId: 'us-east-1_******',
userName: 'uname',
callerContext: {
awsSdkVersion: 'aws-sdk-unknown-unknown',
clientId: '<my_client_id>'
},
triggerSource: 'DefineAuthChallenge_Authentication',
request: {
userAttributes: {
sub: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
'cognito:email_alias': '<email>',
'cognito:user_status': 'CONFIRMED',
email_verified: 'true',
name: 'Custom Test',
email: '<email>'
},
session: [], -----> !! Empty
userNotFound: false
},
response: { challengeName: null, issueTokens: null, failAuthentication: null }
}
What is the reason? Is it because I am sending the request from CLI so Cognito not able to create a session or something? I'm not sure. Any help will be appreciated.
Session holds previous auth challenge results (either from built-in challenges or you custom challenges). It will be empty for the first invocation of the define auth challenge lambda. As the name suggests you have to define the auth challenge in the handler response.
I'm newbie to firebase.
I'm trying to make a signup component using firebase authentication, but the user object I've got returned from firebase.auth().createUserWithEmailAndPassword doesn't seem to be right.
The official document says that I can get the uid by calling user.uid, but in my case it returns null. Instead, I can get uid by calling user.user.uid.
I'm so confused.
Is the document I'v seen was outdated? or have I done something wrong?
Detailed codes are below. Please take a look and give me a piece of advice.
const promise=firebase.auth.createUserWithEmailAndPassword(email, password);
promise
.then((user) => {
console.log(user);
console.log(user.id); //returns null
console.log(user.user.uid); //returns O6hLcfJL5NT4fV2S7JprQ3MhjCK2, which I assumes to be uid.
})
.catch((e) => {
console.log(e.message);
})
Following are the result of console.log(user).
{user: P, credential: null, additionalUserInfo: Wf, operationType: "signIn"}
additionalUserInfo: Wf {providerId: "password", isNewUser: true}
credential: null
operationType: "signIn"
user: P {G: Array(0), l: "AIzaSyDIj8N9kONUkpOdMGuApNcKkaeFYYEzfyk", o: "[DEFAULT]", u: "bluegenie-2ba45.firebaseapp.com", c: bi, …}
__proto__: Object
As you can see, there is another user object inside the user object which I've got returned from createUserWithEmailAndPassword() method.
Thanks in advance.
createUserWithEmailAndPassword returns a promise that resolves with a UserCredential instead of a User.
This change was made in v5.0.0