Is there any api to find out screen name by passing the email address as the input in liferay for LDAP configuration?
You'll need to get a request object, then do this
long companyID = PortalUtil.getCompanyId(request)
User user = UserLocalServiceUtil.getUserByEmailAddress(companyID, emailAddress);
String scrName = user.getScreenName();
EDIT : in your liferay control panel/portal/authentication/LDAP, there is field named 'user search filter'
use (cn=#screen_name#) if your users are logging with screenName
use (mail=#email_address#) if your users are logging with email address
This way you're supposed to import the users automatically.
Please update your question. According to your tags, it looked like you're searching for a Liferay API. If you wanted an LDAP API you should write it somewhere
Related
I've been trying to get the email of a Jira user other than my own with the Python3 Jira library, but couldn't do it. It either gives me an error, saying I don't have enough permissions to get it, or only returns me simple information, like display names. Here's my code:
from jira import JIRA
conn = JIRA(
options={"server": "https://example.atlassian.net"},
basic_auth=("my.email#gmail.com", TOKEN),
)
conn.user(id='my_id').emailAddress # Returns my email and more information
conn.user(id='another_user_id').emailAddress # Doesn't return his email
How could I get someone's email?
And what kind of permissions could I need?
To access another user's email in Jira, you'll need to have the "View User" permission in Jira. You can check this by navigating to the Jira administration page, clicking on Users, and checking the permissions for the user you want to access. If you do not have the "View User" permission, you will not be able to retrieve the email address of another user.
If you do have the "View User" permission, but still cannot retrieve the email address, you could try the following code:
from jira import JIRA
conn = JIRA(
options={"server": "https://example.atlassian.net"},
basic_auth=("my.email#gmail.com", TOKEN),
)
user = conn.user(id='another_user_id')
email = user.emailAddress
print(email)
Note that the emailAddress property is only available in Jira versions 7.3 and later. If you're using an earlier version of Jira, you may need to upgrade to access this property.
I'm trying to create a custom "from" send-as alias (sendAsEmail) with Gmail API and Google Admin: https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/create
I'm getting a 400 error with sendAsEmail is not a valid user or group.
In Google Admin I have a 3 verified domains, all with MX properly registered with gmail services :
#domain-a.com is primary domain
#domain-b.com (not a domain alias)
#domain-c.com (not a domain alias)
user#domain-a.com is a user, with no send-as alias defined.
When I create the sendAsEmail user#domain-b.com, no issue. I can see it appears in gmail.
When I create the sendAsEmail user#domain-c.com, it fails. I can not find out why. If I search for user#domain-c.com in Google Admin to be sure if it is not a group, no result. Any help would be very welcomed.
I'm doing my api calls with PHP, but I dont thing that the issue is related with the language.
Finally found a solution. There was actually multiples causes :
Google Admin :
First on Google Admin side, I had to create an alias : https://developers.google.com/admin-sdk/directory/v1/guides/manage-user-aliases. If you dont do this, the Gmail sendAsEmail creation will fail. Note that the Client HTTP used to do this call needs to use an admin user :
<?php
putenv('GOOGLE_APPLICATION_CREDENTIALS=./client_secrets.json');
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials(); // loads whats in that json service account file.
$this->client->setScopes([
Google_Service_Directory::ADMIN_DIRECTORY_USER,
Google_Service_Directory::ADMIN_DIRECTORY_USER_SECURITY,
Google_Service_Directory::ADMIN_DIRECTORY_USER_ALIAS
]);
$this->client->setSubject('admin#domain.com');
Gmail :
Create a sendAsEmail like explained here : https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/create
Note that the Client Http used to do this call needs to impersonate the user :
<?php
putenv('GOOGLE_APPLICATION_CREDENTIALS=./client_secrets.json');
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials(); // loads whats in that json service account file.
$this->client->setScopes([
Google_Service_Gmail::GMAIL_SETTINGS_BASIC,
Google_Service_Gmail::GMAIL_SETTINGS_SHARING
]);
$this->client->setSubject('user#domain.com');
I want to add a login with Microsoft button to my mean-stack application. So I am using passport-microsoft.
By using passport.authenticate('microsoft', { scope: ['User.Read'] }), I could get these information: #odata.context, givenName, surname, displayName id, userPrincipalName, businessPhones, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage. For me, my userPrincipalName is an email address, whereas my mail is null.
I have setup the application as follows, but if I write passport.authenticate('microsoft', { scope: ['User.Read', 'email'] }), the authentication gave me an "invalid scope" error.
Does anyone know how to setup my application and request to get the email address of a user?
If you look at the documentation for the user object, you will find the following:
mail
String
The SMTP address for the user, for example,
"jeff#contoso.onmicrosoft.com". Read-Only. Supports $filter.
userPrincipalName
String
The user principal name (UPN) of the user. The UPN is an
Internet-style login name for the user based on the Internet standard
RFC 822. By convention, this should map to the user's email name. The
general format is alias#domain, where domain must be present in the
tenant’s collection of verified domains. This property is required
when a user is created. The verified domains for the tenant can be
accessed from the verifiedDomains property of organization. Supports
$filter and $orderby.
So it seems the mail property does not necessarily represent the email address for the user, but is used specifically with Outlook and Office 365. It is also not a required property when creating a user. Instead, you should rely on the userPrincipalName to be the email for the user.
As for your error with the scope, you should share the full error message.
I am trying to integrate azure Active Directory Authentication Library for js to my site. I downloaded the SPA sample and made it work with my app detail.
However, how can I pass user information back to server?
For example, this is the example code on server side to retrive the logged in user:
string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
IEnumerable<Todo> currentUserToDos = db.Todoes.Where(a => a.Owner == owner);
The owner string turned out to be a guid like token other than a readable username or email address.
Is there a way to retrieve username or email address by using this library directly or I have to send it to server side myself?
ClaimTypes.NameIdentifier is a guid unique to each user. If you want readable username or email address, try ClaimTypes.Email or ClaimTypes.Name.
Yes, we are able to get the user info from client directly via adal-angular.js. It already store the user information to the $rootScope. userInfo, we can retrieve the user information from it instead of from web server.
Here is the code that retrieve the name and email address:
console.log($rootScope.userInfo.userName);
console.log($rootScope.userInfo.profile.name);
console.log($rootScope.userInfo.profile.upn);
And below is a figure for the struct of userInfo object for your reference:
In my liferay application I am adding application users by using Expando programatically and not using liferay default User signup.
Now I want to send credentials to user to his email address using liferay default templates available from Control Panel - Portal Setting - Email Templates.
How can I trigger email using this liferay inbuilt template?
Any hint is appreciated.
Liferay uses template files(.tmpl) files to manage Email templates.
As per the Liferay Source,for User creation,given snippet is used to send out mail to users.
String body = PrefsPropsUtil.getContent(
user.getCompanyId(), PropsKeys.ADMIN_EMAIL_USER_ADDED_BODY);
SubscriptionSender subscriptionSender = new SubscriptionSender();
subscriptionSender.setBody(body);
subscriptionSender.setCompanyId(user.getCompanyId());
subscriptionSender.setContextAttributes(
"[$USER_ID$]", user.getUserId(), "[$USER_PASSWORD$]", password,
"[$USER_SCREENNAME$]", user.getScreenName());
subscriptionSender.setFrom(fromAddress, fromName);
subscriptionSender.setHtmlFormat(true);
subscriptionSender.setMailId(
"user", user.getUserId(), System.currentTimeMillis(),
PwdGenerator.getPassword());
subscriptionSender.setServiceContext(serviceContext);
subscriptionSender.setSubject(subject);
subscriptionSender.setUserId(user.getUserId());
subscriptionSender.addRuntimeSubscribers(toAddress, toName);
subscriptionSender.flushNotificationsAsync();
This is part of service impl class UserLocalServiceImpl.
Here "PropsKeys.ADMIN_EMAIL_USER_ADDED_BODY" is the path of the template for body content(default used by liferay).You can populate your custom data in the provided template.
Edit:
After you perform your custom logic,you can directly call
UserLocalServiceUtil.sendPassword(
long companyId, String emailAddress, String fromName,
String fromAddress, String subject, String body,
ServiceContext serviceContext)
method directly from custom class,which will take care of using liferay template as well as password management.