Key cloak user role mapping - keycloak

when I POST the user role-mapping REST it gives the following an error response, please give your kind advice to solve this issue.
http://127.0.0.1:8080/auth/admin/realms/{realm}/users/2d6b3636-30da-4bf1-9f1c-54582a348bca/role-mappings/realm
Query param - {"id":"dec8e3f4-3a3a-4f5d-8951-c78236134ace","name":"offline_access"}
response - {"error": "unknown_error"}

Related

Supabase how to query the same table twice

I have been experimenting with Supabase recently and trying to make a twitter like 'replying to #user' comment feature.
So I have a database ERD attached below for reference, As you can see each comment has a userid and also a 'replyingTo' which also stores the userid of the comment which is being replied to.
Now I'm able to query individually between these two tables, So I can get the user of comment along with the comment very easily but however, When I'm trying to fetch the user profile of the comment creator and the profile of replyingTo, I get the following error -
Could not embed because more than one relationship was found for 'Comments' and 'profiles'
I'm not too experienced at PostgreSQL so I'm not sure how to do something of this scope, This is the following code I'm using currently which is giving me the error I have described above.
const { data, error } = await supabase
.from('Comments')
.select('ReplyingTo, profiles:profiles(id), profiles:profiles(id)')
.eq('commentid', cmtid)
My expected outcome is to get the comment, the user profile who created the comment and also the profile of the user who is receiving a reply.
Thank you for your time and patience.
As the error says, the problem is that you have two relationships between profiles and Comments. For this case, you'd need to disambiguate(which foreign key column you want to use for the join) as specified in the PostgREST docs. For the supabase js client, it should be like:
const { data, error } = await supabase
.from('Comments')
.select('ReplyingTo, profiles1:profiles!userid(*), profiles2:profiles!ReplyingTo(*)')
.eq('commentid', cmtid)

REST-API users.list with the eppn

Since we have some integrations with Rocket.Chat, we do use the API to create, query and subscribe User of a System to the Rocket.Chat.
We use the SAML authentication and we work with the eppn parameter.
Before it was easy to search for a user in rocket chat with the eppn, since you could query the eppn with the API users.list.
api/v1/users.list?query={"eppn":"eppn-of-user"}
After I upgraded the Rocket.Chat to the 3.9 Version, I saw that it is not possible to query the eppn with the users.list API.
The structure of User is changed and now the eppn parameter is a child of services.saml.
I can query the eppn in the MongoDB like this:
coll.find({'services.saml.eppn': "user-eepn"})
But no way to query the eppn with the API:
api/v1/users.list?query={'services.saml.eppn': "user-eppn"}
{
"success": false,
"error": "Invalid query parameter provided: \"{'services.saml.eppn': \"user-eppn\"}\" [error-invalid-query]",
"errorType": "error-invalid-query",
"details": {
"helperMethod": "parseJsonQuery"
}
}
Does anyone have an idea about it?
Thank you!
So everyone, I just got the solution to my problem, if any one will have the same problem.
First of all for the EJSON parse function the query must be written like this:
api/v1/users.list?query={"services.saml.eppn": "user-eppn"}
But the second problem is that Rocket.Chat doesn't allow a query on the services parameter.
It is a problem of permissions, so to query the services parameter and then the eppn parameter, there must be permission given to the User.

Security on GET with query params

I have a dilemma. What do you return for a GET REST request where a user doesn't have the right to use a certain query param.
For example : GET /transactions?user=admin
If an user, that is not the admin tries the following example, what should be the proper response 403 or an empty list?
He has the right to search for any other user, but not the user admin.

REST GET URL Naming

What is the best way to design or name an API URL that would get a specific user with a given unique identifier? I'm using cognitoId as the unique identifier.
Which of the following should I use?
/profiles/profile, then pass the cognitoId as URL Query String Parameters
/profiles/{id}
/profiles/profile then check 'Invoke with caller credentials'
If it is an API where any authorized user can get anyone's username by passing a unique ID, then you could use something like this: /profiles/{id} For example, https://api.github.com/user/1
If it is an API that returns the username of the caller by using the cognito ID, then /profiles/profile should work. See $context.identity variables in documentation to fetch the cognito ID.

How Can I filter Facebook Events Using Location by FQL

How Can I fitler Facebook Events Using Location By FQL
ex. I want to get all event which will be in Egypt
SELECT name FROM event
WHERE strpos(lower(name), 'Egypt') >= 0
https://developers.facebook.com/tools/explorer?fql=SELECT%20name%0AFROM%20event%20%0AWHERE%20strpos%28lower%28name%29%2C%20%27Egypt%27%29%20%3E%3D%200
But when I try to use the above Query it returns that for me:
Your statement is not indexable. The WHERE clause must contain an
indexable column. Such columns are marked with * in the tables linked
from http://developers.facebook.com/docs/reference/fql
Note : I hope to get the public events filtered by event name contains.
With the changes that they have made, queries using an app access_token cannot
use the above query:
SELECT name,location FROM event WHERE contains('egypt')
The query works with session tokens (user access_tokens), however, with an app access_token
it just returns:
{
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
It was surprising to me since I could still use any other query else than contains on the events table with an app access_token
UPDATE:
After looking at their documentations, I found out that you can only use the app access token for very limited set of queries:
https://developers.facebook.com/docs/reference/api/search/
What I finally did was I used the following to obtain a session access_token from my user as a page_manager
https://www.facebook.com/dialog/oauth?client_id={MY_CLIENT_ID}&scope=manage_pages&redirect_uri={MY_REDIRECT_URI}&response_type=token
The above query returns your your access_token and you can use it to run your query successfully. What it basically does is that it appends your access_token to you as a hashed attributed
{MY_REDIRECT_URI}#access_token={MY_ACCESS_TOKEN}
If you would like to parse the access token on the server, this would not work for you, since the hashed attribute is not sent with the request to your server. What you can do is to append type=web_server to the above request to facebook. In that case the access_token will be returned as a request parameter named code
The closest you can get is to use the contains predicate
SELECT name,location FROM event WHERE contains('egypt')
Which will get you some events that contain "egypt" in the text