Can i import users from LDAP to Keycloak only the first time they logged in to Keycloak? - ldap

In the Keycloak documentation, under Synchronizing LDAP users to Keycloak, it says:
If you set the Import Users option, the LDAP Provider handles
importing LDAP users into the Keycloak local database. The first time
a user logs in, the LDAP provider imports the LDAP user into the
Keycloak database and validates the LDAP password. This first time a
user logs in is the only time Keycloak imports the user. If you click
the Users menu in the Admin Console and click the View all users
button, you only see the LDAP users authenticated at least once by
Keycloak. Keycloak imports users this way, so this operation does not
trigger an import of the entire LDAP user database.
But.. actually, I get the exact opposite behavior. When I add LDAP configuration to Keycloak (v.20), it immediately syncs all the LDAP users to my Keycloak users list. How can I import just the users only on the first time a user logs in, as the documentation states.
the configuration I use:
{
providerId: 'ldap',
providerType: 'org.keycloak.storage.UserStorageProvider',
name: 'ldap',
config: {
enabled: ['true'],
connectionUrl: [''],
bindDn: [''],
bindCredential: [''],
startTls: ['false'],
useTruststoreSpi: ['ldapsOnly'],
connectionPooling: ['false'],
authType: ['simple'],
allowKerberosAuthentication: ['false'],
useKerberosForPasswordAuthentication: ['false'],
cachePolicy: ['DEFAULT'],
connectionTimeout: [''],
usersDn: [''],
usernameLDAPAttribute: ['sAMAccountName'],
rdnLDAPAttribute: ['cn'],
uuidLDAPAttribute: ['objectGUID'],
userObjectClasses: ['person, organizationalPerson, user'],
customUserSearchFilter: [''],
readTimeout: [''],
batchSizeForSync: [''],
vendor: ['ad'],
editMode: ['READ_ONLY'],
searchScope: [''],
pagination: ['false'],
importEnabled: ['true'],
syncRegistrations: ['false'],
usePasswordModifyExtendedOp: ['false'],
validatePasswordPolicy: ['false'],
trustEmail: ['false'],
changedSyncPeriod: ['-1'],
fullSyncPeriod: ['-1'],
},

Related

Nuxt JS - Login via API auth methods

I use to login via schema configuration (nuxt.config.js):
strategies: {
/**
* #description OAuth 2.0 authentication scheme
* {#link https://auth.nuxtjs.org/reference/schemes/oauth2}
*/
keycloak: {
_scheme: 'oauth2',
client_id: CLIENT_ID,
authorization_endpoint: NUXT_ENV_AUTH_LOGIN,
userinfo_endpoint: NUXT_ENV_AUTH_USER_INFO_ENDPOINT,
access_token_endpoint: NUXT_ENV_AUTH_ACCESS_TOKEN_ENDPOINT,
response_type: 'token id_token',
token_type: 'Bearer',
token_key: 'access_token',
scope: ['openid', 'profile', 'email'],
},
},
and it work perfectly using the classic form login.
Now i would like to login a user without a form but starting from a valid access_token generated by a CURL (curl or whatever....).
At the moment i can't figure out how to make it work. I tried to invoke methods like explained here https://auth.nuxtjs.org/api/auth/#refreshtokens but without a good result.
What's required to be loggog in, i suppose is to have a token set into localStorage and cookie (as i see post a normal login) and set the user data into the nuxt store.
Thank you for any advice.

AWS Amplify API authentication error for unauthenticated user

I created a books API with Amplify for an iOS app. I want the book table to have read access for both authenticated and unauthenticated users. Here's the schema:
type Book
#model
#searchable
#auth(
rules: [
{allow: private, provider: userPools, operations: [read]},
{allow: groups, groups: ["Admin"]}
]
)
{
id: ID!
category: BookCategoryType!
description: String
groupsCanAccess: [String]!
images: [Image!]
#auth(rules: [
{allow: groups, groupsField: "groupsCanAccess", operations: [read]},
{allow: groups, groups: ["Admin"]}
])
title: String!
}
However, when calling fetch from AWSAppSyncClient, I get the following error:
authenticationError(AWSMobileClient.AWSMobileClientError.notSignedIn(message: "User is not signed in, please sign in to use this API."))
The Cognito identity pool has Enable access to unauthenticated identities checked and there's an unauth IAM role.
What could be the problem?

Authentification with ldap without user's password

I am trying to create login authentication with ldap js. I set up all Credentials and everything is working fine, but the problem is I can bind a user just with his Uid (user id aka username), it didn't ask for a password and I don't know how to fix this it must ask for Uid and userPAssword to connect
I tried to connect to with the same credentials including userPassword but it didn't work for me
ldapConfig.js
in this file i set up all ldap config
'url': 'ldap://*************',
'port': '***',
'timeout': '',
'connectTimeout': '',
'secret': '**********',
'reconnect': true,
'filtre': '(&(ObjectClass=*******)',
'search_dn': 'ou=******,dc=****,dc=****',
'domain': 'cn=******,dc=****,dc=****'
login.js
in this file i tried to connect to ldap server and it work realy fine and then i want to get user by uid
const server = ldapConfig.url
const ldapDomain = ldapConfig.domain
const password = ldapConfig.secret
const searchDomain = ldapConfig.search_dn
const client = ldap.createClient({
url: server
})
client.bind(ldapDomain, password, err => {
assert.ifError(err)
})
const opts = {
scope: 'sub',
filter: ldapConfig.filtre + `(mail=${request.body.mail}))`
}
client.search(searchDomain, opts, (err, res) => {
assert.ifError(err)
res.on('searchEntry', entry => {
console.log(entry.object)
} )
I hope it's clear . Thanks
Unauthenticated bind (a seemingly successful bind when you supply a userID and null password) may be enabled in your directory. If you are using OpenLDAP, as the quesstion tags indicate, check slapd.conf for allow bind_anon_cred.
Unless there is a specific need for unauthenticated bind, I disable it on the directory servers. In the rare cases where unauthenticated bind is required, all applications authenticating against the directory need to validate user input before attempting to bind -- that is, verify that the input username and password values are not null.

Sequrity in Authentication a user

I write toy-server on Node and i want to create system authentication a user. For that purpose i install express and express-session.
This setting exprerss-session
app.use(session({
key: 'user_sid',
secret: 'somerandomstuffs',
resave: false,
saveUnitialized: false,
cookie: {
expires: 600000 }
While new user signup or a user login, i regenerate session with the function - res.session.regenerate() and create new the req propertie
req.session.user = User.dataValues
The problem is begin if the user want to edit his account. I think do this
if(req.session.user && req.cookies.user_sid)
{ user can change his account }
else { res.redirect('/login') }
But i'm afraid this is not enough. I want not install another program, i want make this as simple as i could.

Can I create an AWS Cognito user login programmatically?

I would like my app to allow users with a Facebook, Google, Amazon... etc... accounts to be able to login to my app. This works fine through AWS Cognito.
However, is there a way for the app to create a user login programmatically if the user does not have any of those logins?
The user would provide an id and a password and the app would send the information to the authentiation provider to create a new login/account.
I would not need to implement my own authentication mechanism and worry about how the passwords are stored, etc.
From my research I take that there is no way to do this with existing authentication providers or even other services such as OpenID.
Do you have any other options if I do not want to implement my own login storage and authentication? It would not necessarily need to integrate with AWS Cognito.
I'm a little confused by your question. If you're asking:
Can I create new usernames and passwords on Facebook / Google programatically?
Then the answer is no. You have to sign up for Facebook / Google on their site. If you're asking:
Can I create a new user with a username and password that only exists in Cognito?
Then the answer is yes. To do this, it depends on whether you're creating the user in a browser or on a server. In a browser, use the Cognito Javascript API. On a server, use the Cognito Admin Server APIs.
Here's some sample code for creating a new user on the server in Node JS (replace my strings with your own tokens, especially the ones with # signs in them):
let params = {
UserPoolId: "#cognito_pool_id#",
Username: "jhancock",
DesiredDeliveryMediums: ["EMAIL"],
ForceAliasCreation: false,
MessageAction: "SUPPRESS",
TemporaryPassword: "somePassword",
UserAttributes: [
{ Name: "given_name", Value: "John"},
{ Name: "family_name", Value: "Hancock"},
{ Name: "name", Value: "John Hancock"},
{ Name: "email", Value: "john#gmail.com"},
{ Name: "phone_number", Value: "+15125551212"}
],
};
console.log("Sending params to cognito: " + JSON.stringify(params));
let cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({region: "us-east-1"});
cognitoIdentityServiceProvider.adminCreateUser(params, function(error, data) {
if (error) {
console.log("Error adding user to cognito: " + JSON.stringify(error), error.stack);
} else {
console.log("Received back from cognito: " + JSON.stringify(data));
}
}
One you get that working, you'll probably want to see this post about how to change the temporary password into a real one.
Hi from my previous experence in implementing of the social media authentication.
I would conclude that it is quite hard to implement.If you do not what to show web view to authenticate user in iOS you need to use iOS ACAccountStore class for this, but even this only gives opportunity to log in not to sign in.