Can't get the newly created user in the list of all users - desire2learn

I sent a request to
/d2l/api/lp/1.30/users/
and created new student.
This is my request params
{
"OrgDefinedId": 'testId',
"FirstName": 'testUser222',
"MiddleName": '',
"LastName": 'LastName',
"ExternalEmail":'xxx#xxx.io',
"UserName": 'Sam',
"RoleId": '110',
"IsActive": true,
"SendCreationEmail": true
}
I can get this user using get request
/d2l/api/lp/1.30/users/344
I also activated this user by email and set new password.
I can login as this user at LMS.
But, i can't get this user using this request
/d2l/api/lp/1.30/users/
This user is not in the general list of users
What have I done wrong? Maybe I need some other additional request in order for it to be displayed in the general list of users?

I am assuming you are referencing this route - https://docs.valence.desire2learn.com/res/user.html#get--d2l-api-lp-(version)-users-
In order to have the user included in this call's response your api user account needs to have the "Users - Search for 'xxx-role'" permission enabled.
This route does page its response, so you may have to page through the response to find the specific user.
This route does support query parameter filtering, which will reduce the number of users included in the response.

Related

how to get the roles in access token: keycloak

what I am trying to do:
I have an app that takes in login credentials: username and password for a user. I have a rest api that internally calls the keycloak REST API: /auth/realms/realmname/protocol/openid-connect/token
and gets the access token for this user.
Now I am building another REST API to access a resource where I want to do the following:
doSomething(accesstoken, data)
{
a) call keycloak API to validate access token and get roles.
b) if role == manager, process(data)
c) else: return error msg.
}
Now, how do I do (a): validating the access token and getting the roles associated with it.
I know we can do: auth/realms/realmname/protocol/openid-connect/userinfo
but that only gives the details about the user like name, email, etc. but does not display any roles.
Here's an example I got:
{
"name": "test user",
"sub": "e2bad34d-a1a9-4d70-ac84-bd3a3246023e",
"email_verified": false,
"preferred_username": "user",
"given_name": "test",
"family_name": "user"
}
As seen, it doesnt give the roles at all. How do I then tell what roles this access token has? Interestingly, when I search for this, many resources are suggesting the above userinfo endpoint. But this merely tells me taht the access token I provided is valid. Does not give roles for that.
In other words - it authenticates but does not authorize.
Please suggest.
Thanks,
Anand
In Keycloak admin Console, you can configure Mappers under your client. Add a builtin Mapper of type "User Realm Role", then open its configuration e.g. change Token Claim Name if you want.
Client roles can be configured similarly, but they are returned by default in the token under the name resource_access.${client_id}.roles
The the client side you can parse the token to find the roles. E.g. In an angular application and using the keycloak-angular adapter, you can have a the token as a json object by calling keycloak.getKeycloakInstance().tokenParsed.
In a spring boot application and using the Keycloak java api, you can find the roles under the field "otherClaim" in the following class
https://www.keycloak.org/docs-api/10.0/javadocs/org/keycloak/representations/AccessTokenResponse.html
In both representations you will find the roles under the "Token Claim Name" defined in the client mapper configuration
Additionally, if the full scope is not allowed then you need to add the relevant roles to the scope, so they can appear in the token.
After adding role in the roles section , need to move available roles into the Assigned Roles of the scope tab of the respective client section.

Does Survey Monkey Have any API to Save User Information, I want to save visitor name and email when he start the survey

I want to save visitor information into survey monkey dashboard for analytics purpose. Not sure how I can do this. We get the user information from FB like user name and email, when user click on start the survey button I want to save this information. Can anyone Help on this or this is possible using surveymonkey API.
You could potentially store them as a contact in your contact list.
Example:
POST /v3/contacts
{
"first_name": "test",
"last_name": "example",
"email": "test#example.com"
}
With contacts they are unique by email so if you try to create another contact for the same user it should overwrite the previous one. You can look more into contacts in the help center.

Getting Facebook Page's Ratings

I am looking to pull a public Facebook page's ratings into a Ruby on Rails app.
Essentially what I'm looking to do is run a rake task as a cron job that looks for new reviews on one particular Facebook page (the page I need will not change) and pulls them into the app. I've explored Facebook's API and the Koala gem and can't get to the page data. I'm just not sure how I can get an access token outside a browser. In addition, if I were to get the access token, it doesn't seem I can get to the ratings data without being the owner of the page.
One route I took was to send a simple GET request to the page. Something like https://graph.facebook.com/{page-id} works fine, but https://graph.facebook.com/{page-id}/ratings throws the following:
{
"error": {
"message": "(#210) Subject must be a page.",
"type": "OAuthException",
"code": 210
}
}
What is the simplest way to get to this data?
As mentioned in the question's comments, I needed to be authenticated as a Facebook user with admin access to the Facebook Page of interest because I need to get a token from that.
After getting access to the page, I accomplished the API call via the Koala gem. I initialized Koala with the app:
config/initializers/facebook.rb
$facebook = Koala::Facebook::OAuth.new(
"my_facebook_app_id",
"my_facebook_secret",
"my_facebook_redirect_url"
)
Since I only needed to get the token for one user in one scenario, I did so via the admin side of my app, in my facebook_controller.
In this controller action, I look for the code parameter in the route. If we don't find it, we send to the authorization url, otherwise we process and store the Facebook user token in the User model in a pre-determined and predictable record.
app/controllers/admin/facebook_controller.rb
def auth
if params[:code].present?
code = params[:code]
token = $facebook.get_access_token_info(code)
User.find_by_email('admin#example.com').update(
:fb_access_token => token['access_token'],
:fb_token_expires => token['expires'].to_i.seconds.from_now
)
redirect_to admin_dashboard_path
else
redirect_to $facebook.url_for_oauth_code(:permissions => "manage_pages")
end
end
Once I have an active token, I can acquire the page token like so:
user = User.find_by_email('admin#example.com')
user_graph = Koala::Facebook::GraphAPI.new(user.fb_access_token)
accounts = user_graph.get_connections('me', 'accounts')
page_token = accounts[0]['access_token']
page_graph = Koala::Facebook::API.new(page_token)
ratings = page_graph.get_connection('me', 'ratings')
At this point, I have the collection of ratings objects stored in the ratings variable. I can do whatever I need with these ratings at this point.
Note: In this particular case, I new the Facebook Page was the first account in the array of user accounts. This took some trial and error, but can be accomplished by iterating over the user accounts array (in this case, stored in accounts) if you can't predict the index of the desired account.
It seems to be a bug of Facebook Graph API. I have exactly the same problem.
I can get lists of all other objects but I do get an error when requesting /{page-id}/ratings. The JSON payload returned by Facebook Graph API is the following:
{
"error": {
"message": "(#210) Subject must be a page.",
"type": "OAuthException",
"code": 210
}
}

Facebook real time update

I am trying to use facebook real time updates in my rails app.
I added realtime update fields for "user" and "email" object in facebook settings page with the following parameters:
Object: user
Fields: email, likes
Callback: http://fb-realtime-test.herokuapp.com/facebook/subscription
Verify Token: stringToken
I can also able to get a subscriptions for the fields i subscribed.
The URL
https://graph.facebook.com/141213822708267/subscriptions?access_token=141213822708267|-drf6Izviu3BSJ1YgU-Dx5Wi0GY&method=get
Returns
{
"data": [
{
"object": "user",
"callback_url": "http://fb-realtime-test.herokuapp.com/facebook/subscription",
"fields": [
"email",
"likes"
],
"active": true
}
]
}
I also added permission for "user_likes" and "email" when the user login.
But i am not able to see the POST call from Facebook if any likes or email is modified.
Please guide me what i am doing wrong. Thank you.
Problem fixed. I am not able to get POST callback from facebook because i hosted my rails app n heroku. With Heroku it limits for single process thus i got only GET from facebook but not POST. Heroku blocks other processes with single dyno. To support that we need to get two dynos to get post callback from facebook.

devise how to sign in a user after post from external url

I have a form on an site1.com that POST a devise user object to site2.com/users.
It works but the user is not signed in. I see it may be related because there's no CSRF token on the form on site1.com.
I'm a bit lost in how to solve this. Should I do an ajax call from site1.com to site2.com before the POST just to retrieve the CSRF? Any idea what would be a preferred way to do this?
depending on your site2 if it supports, you can post JSON over http
something like this
{"username": "", "password": "password", "application": ""}
it will be up to your second site how it processes.

Resources