0.0.9 • Published 2 years ago
apollo-datasource-ldap v0.0.9
apollo-datasource-ldap
LDAP datasource for apollo graphql server
Sample server
const { ApolloServer, gql } = require("apollo-server");
const {
LdapDataSource,
resolvers,
typeDefs,
} = require("apollo-datasource-ldap");
const ldap_config = require("./ldap.json");
var ldapDS = {};
Object.keys(ldap_config).map(function (key, index) {
ldapDS[key] = new LdapDataSource(
key,
ldap_config[key].user,
ldap_config[key].password,
ldap_config[key].basedn,
ldap_config[key].options
);
});
const graphqlSchemaObj = {
typeDefs: typeDefs,
resolvers: resolvers,
tracing: true,
dataSources: () => ldapDS,
plugins: [responseCachePlugin()],
cacheControl: {
defaultMaxAge: 3600, // 3600 seconds
},
};
const server = new ApolloServer(graphqlSchemaObj);
// The `listen` method launches a web server.
server.listen({ port: process.env.PORT }).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
ldap.json
{
"ldap_xxx": {
"user": "xxx\\matteo",
"password": "mySillyPassword",
"basedn": "DC=xxx,DC=redaelli,DC=org",
"options": {
"url": ["ldaps://domaincontroller.xxx.redaelli.org"],
"timeout": 0,
"reconnect": true,
"tlsOptions": {
"requestCert": false,
"rejectUnauthorized": false
}
}
}
}
Sample queries
{
ldap_search(
ldap_id: "ldap_xxx"
basedn: "dc=xxx,dc=redaelli,dc=org"
filter: "(samaccountname=server1)"
) {
... on LdapComputer {
sAMAccountName
dNSHostName
ipaddress
}
}
}
{
ldap_search_computer(
ldap_id: "ldap_xxx"
basedn: "dc=xxx,dc=redaelli,dc=org"
filter: "(samaccountname=server1)"
) {
sAMAccountName
dNSHostName
ipaddress
}
}
{
ldap_search_group(
ldap_id: "ldap_xxx"
basedn: "dc=xxx,dc=redaelli,dc=org"
filter: "(samaccountname=qliksense_plant1)"
) {
dn
memberExt {
... on LdapUser {
mail
}
... on LdapGroup {
dn
}
}
}
}
{
ldap_search_user(
ldap_id: "ldap_xxx"
basedn: "dc=xxx,dc=redaelli,dc=org"
filter: "(samaccountname=matteo)"
){
sAMAccountName
pwdLastSetExt
pwdLastSetDays
lockoutTime
locked
lastLogonTimestampExt
managerExt {
cn
managerExt {
cn
managerExt {
cn
}
}
}
}}
TODO
- LdapComputer type
- GroupComputer type
- UserComputer type
- other ldap types