CUBA Platform get username in Polymer UI - polymer

What is the proper way to get a session parameters (like username of currently logged user) in Polymer UI.
I've expected something like:
Your login: [[msg('session$userLogin')]]
but not works

Currently there is no direct access to session params in Polymer UI. If you just need to display user login there is a special method in REST API.
Here is the example of a component which loads and displays user login: https://gist.github.com/web-devel/3659ef13ccaefc6597e1ae649dcb42cf
If you need to access other session params you can create a middleware service and make it available in REST API

Related

PluggableAuth extension how to receive $_POST hidden data without show form to user?

I created a simple authentication extension that works in conjunction with PluggableAuth for the user to login automatically. Currently, I need two parameters: a username and a token. These parameters are generated by an external system that sends the data by hidden input. I can get the url data and authenticate correctly. But for security reasons I want to pass this data via $_POST and not via $_GET. But I cannot receive this data and store it in the session so that I can retrieve it in my authentication class. Basically, the user receives a link from a wiki page and Pluggableauth does the checks. But I can't find what code I can use to save the post in the session and retrieve it later. Does anyone have any examples of how to do this? Thanks!
Edit: For example, the user needs to go to www.minhawiki.com/something, the external system sends the post data with username and password to this example page, but because of pluggableauth it redirects to Special:UserLogin, then to PluggableAuthLogin and then to my authentication extension. I've tried to get the data on all these redirects but none of them work. The only way that worked to get the data was to direct the post directly to Special:UserLogin but that way I can't redirect to the login page.

Pass Authentication Token to Service

I have used lifeary service builder to build my services. some of my services require that the user is authenticated before he can use them.
how can i generate an auth token and send it in the header or in the URL?
I have tried username#host.com:password#http://localhost:8080/PortletName-portlet/api/jsonws/?serviceClassName=com.service.NameServiceUtil&serviceMethodName=getMyNames&serviceParameters=[userid]&userid=1
and it did not work!
I have made sure i have added the below line in my portal-ext.properties and restarted the server.
json.service.auth.token.enabled=true
What more should i do to be able to pass Auth Token? is there a better method that i can use?
You actually want to use AuthVerifier. This is the best way how to access the Liferay API and be authenticated. It similar to the autologin concept.
Have a look at https://dev.liferay.com/es/discover/deployment/-/knowledge_base/7-0/authentication-verifiers and check out the PortalSessionAuthVerifier class in the source code.
The concept is quite simple. Read the request object and determine who the user is. Perform your custom authentication and return the auth result with the user identification.

Integrating Grafana in to angularjs application with auto login and get user specific dashboard?

I want to integrate grafana into my angularjs web application for monitoring purpose. I want something through which I can redirect to grafana dashboard with credentials by surpassing the grafana login page , means direct dashboard page should be displayed of logged in user of grafana. Session management should be there like dashboard data should be user specific. Please provide details to achieve this, thanks
You can probably use something like grafana auth proxy with a 3rd party authentication service or your own service.
You can load the dashboard by embedding an iframe
http://grafana-reverse-proxy/dashboard/db/{{dashboard}}?orgId=abc
Note: The url points to the reverse proxy which will authenticate your user which you pass from your angularjs app.
Alternatively if you want roles to assigned to your users, you can integrate ldap and map roles to users.
Same can be achieved with generic oauth if you have a auth service.

Using As-User in Box Request

I was trying to make Box Enterprise API work using As-User. I have a admin account which i used to try to retrieve the Contents in a sub account.
I first used the admin account to retrieve the User ID of the sub account. And added the User ID as a field "As-User: ########". However, I was returned with a reply of 403.
The error message : "The request requires higher privileges than provided by the access token."
I am using the access token i had used to retrieve the user list. Do I have to get a new access token using the as the new user? or is the admin access token fine?
GET /2.0/folders/0/items HTTP/1.1\r
Host: api.box.com\r
Authorization: Bearer #######################\r
As-User: ########\r
Connection: close\r
\r
The access code is the same access code used to retrieve the user list /user
All the scopes has been checked
Your application must be manually approved by Box for As-User requests. The documentation mentions this but it's easy to miss. To start the approval process send Box a note and include your API Key.
I am unable to add a comment on this, so I would like to add (in case the support staff doesn't give you a head's up) you may have to do this after they enable the As-User header --
Go back to your - Admin Console->Business Settings->Apps
Find the Custom Applications section
Authorize or reauthorize the app you are working with
I had the same problem and found this:
https://support.box.com/hc/ja/community/posts/360049157874-Insufficent-scope-when-trying-to-make-a-call-using-As-User-header
So you should use the scope admin_on_behalf_of.

JSON API Error - You need to login with a user that has 'edit_posts' capacity

I'm building an app on angular and ionic, I'm trying to access my WordPress and create new post.
I've generated auth cookie using JSON API User plugin (https://wordpress.org/plugins/json-api/)
I've got a valid nonce to create posts.
I'm using all the right parameter to create new post:
$http.post(domain+'/posts/create_post?nonce='+nonce.nonce+'&title='+title+'&content='+content+'&status='+status+'&author='+author)
But when I've tried to insert new post i get this massage:
"Error: You need to login with a user that has 'edit_posts' capacity"
i've that i need to add the cookie parameter to the header request, but i don't understand how.
Please help me to solve this :)
This is about the user's role, not the the auth cookie. The auth cookie would login the user, but their roles and capabilities are stored in the database. There are many ways to change the user's role, including going into the Admin Dashboard as as admin, clicking Users, the user's name, and selecting "Editor" [or whatever is appropriate] in the drop down menu.
For complete details, see https://wordpress.org/support/topic/error-you-need-to-login-with-a-user-that-has-edit_posts-capacity.
But just in case you are having issues with cookie:
Cookie need to be added to the headers like this:
Header:Cookie
Value:<cookie_name>=<cookie>
Also, if you are testing via Postman app from chrome, make sure to enable sending restricted headers (since "Cookie" is a restricted header, for more info see https://www.getpostman.com/docs/requests)