exact param search match with keycloak REST Api - keycloak

I'm using Keycloak REST Api to get users with query param
Get users Returns a list of users, filtered according to query parameters
GET /{realm}/users
with query param ?username=admin, but for this query param value I also get similar results like awadmin username etc. How to get Exact account with admin username

The problem was with older version of docs-api. In latest 12 there is explicitly mentioned
A String contained in username, or the complete username, if param
"exact" is true
https://www.keycloak.org/docs-api/12.0/rest-api/index.html

Related

Microsoft Graph REST API: Filter signIns by Country

I am trying to query the Microsoft GRAPH REST API as follows:
https://graph.microsoft.com/beta/auditLogs/signIns$filter=location/any(c:c/countryOrRegion eq 'CA')
However I am receiving a 400: Invalid filter clause error.
If I do a simple query such as $filter=userDisplayName eq 'Bob Smith' my query works fine.
What is the correct way to filter signIns by Country in Graph?
Syntax for filter sub-property -
$filter=property/subProperty eq 'value-to-match'
You can try using below query
https://graph.microsoft.com/beta/auditLogs/signins?$filter=location/countryOrRegion eq 'IN'
For more info you can check the docs for filter query parameters - https://learn.microsoft.com/en-us/graph/filter-query-parameter

Set up mongodb _id to firebase uid

I'm new to asking questions in Stack overflow.
I'm implementing an application that it's using Firebase Auth for users login, logout and delete account and mongodb with python (pymongo) to manage the database.
When a user signs in, a new user is created in Firebase Auth so the new user is given a new UID which is a 28 characters id (it is a string). My idea is to set the value of the _id from mongodb collection to the uid but it seems that the uid is longer than what it is expected:
Here you can see the output in the python console (An exception occurred :: 'g2CgrpStaOUwEFBpLzuJWme3OMR2' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string)
Do you have any idea to solve this problem? I tried
"_id": ObjectId(str.encode(id)) when creating the document but it says
An exception occurred :: id must be an instance of (bytes, str, ObjectId), not <class 'bytes'> and I'm running out of ideas.
I hope you can help me, I'm glad to hear your questions.
Thanks in advance.
EDIT
As I'm working with Firebase Auth in the frontend (react native + expo app)
#Dharmaraj suggested me to use Firebase Auth admin SDK in the client side so that I can assign a certain uid to the user based on the user _id in mongodb database. Thanks for your suggestion!
The MongoDB object ID is a 12 bytes hex string but Firebase auth's UID is not. You can either store the Firebase UID as string in a different field in document e.g. userId or since your are using MongoDB I assume you must be running this logic on server side. In that case you can first add the user document in MongoDB and use that _ID as Firebase UID. You can specify this custom UID when using Firebase admin SDK
The _id field is mandatory, unique within a collection, and immutable. However it does not have to be an ObjectID.
It often is, as MongoDB will create the field automatically as one, but noting the caveats above, you can set it to a string or indeed any other valid BSON type.
More info: https://www.mongodb.com/docs/manual/core/document/#the-_id-field

Firestore security rules - how to secure LIST requests by request.query checks on ACL access control list?

I want to secure a collection of accounts documents with a field access.users that contains an array of user DocumentReferences which are allowed to access an account document in the collection.
accounts.access.users = [ //array of user document references ]
In my query (JS client library) I am setting the query:
db.collection('accounts').where('access.users', 'array-contains', userRef)
To secure the data, I want to write a rule:
function userHasAccountAccess () {
let user = getUser(); // returns users document reference based on auth uid
// - here - need to check that the users document reference was requested by the query ie - that `request.query` contains the `access.users` field and that value of this filter in an array/list which includes a reference to the users' document
}
match /accounts/{docId} {
list: if userHasAccountAccess();
}
... but it seems from the docs that the only properties available on a query are limit, offset and orderBy, so then I am unable to test or secure this way.
So how are others securing their data in this type of access role ACL scenario for LIST type requests?
So after some digging, I found the answer.
Where posting a query (LIST) request as so:
db.collection('accounts').where('access.users', 'array-contains', userRef).limit(5)
... it seems that limit, orderBy and offset become properties of request.query in the security rules, but the where filters become properties of resource.data.
This is confusing because a) resource.data is usually a map of document data being posted (ie when saving records) and b) the docs describe resource.data as such.

MS Graph API "AND" criteria in $search

I am using the Microsoft Graph API and not getting expected results when using the AND criteria.
If i was to query:
https://graph.microsoft.com/beta/users/{UserGUID}/messages?$search="to:customeraddress.com"
I would get a result containing all emails from that customer.
However if i change the search criteria to
$search="to:customeraddress.ac.uk AND sender:myDomain.com"
or
$search="to:customeraddress.ac.uk AND from:myDomain.com"
some of the emails that were originally returned are now missing even though they are from the mydomain address.
Have i got something wrong?
I have followed information from the following locations:
https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters#search-parameter
https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference
https://technet.microsoft.com/en-us/library/dn774955(v=exchg.160).aspx

Updating Embedded Array And Objects In Mongo

In Mongo I have a collection of post and each post has comments that are embed with a user id, user name and user email.
- post
- comments
- user_id name email
I was wondering how can I update the all the emails that are associated with a certain id?
Currently, you would have to retrieve comments first, and then update emails.
Depending on which client you use, here is a mongoid example:
comments = post.comments
comments.update_attributes(:email => "a#b.c")
Also there is already a "Use positional operator to update all items in an array" JIRA that, once implemented, will allow you to do it in one shot.
Have you tried the $ positional operator, its the only way to update the matching sub(embedded docs) docs.