Skip to content

Commit 21c5509

Browse files
authored
Merge pull request #217 from kuzzleio/credentials-route
Added all new credential related routes
2 parents c71df5d + 838a904 commit 21c5509

File tree

4 files changed

+889
-0
lines changed

4 files changed

+889
-0
lines changed

src/Kuzzle.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,128 @@ Kuzzle.prototype.login = function (strategy) {
520520
});
521521
};
522522

523+
/**
524+
* Create credentials of the specified <strategy> for the current user.
525+
*
526+
* @param credentials
527+
* @param strategy
528+
* @param options
529+
* @param cb
530+
* @returns {Kuzzle}
531+
*/
532+
Kuzzle.prototype.createMyCredentials = function (strategy, credentials, options, cb) {
533+
if (!cb && typeof options === 'function') {
534+
cb = options;
535+
options = null;
536+
}
537+
538+
this.query({controller: 'auth', action: 'createMyCredentials'}, {strategy: strategy, body: credentials}, options, function(err, res) {
539+
if (!err) {
540+
cb && cb(null, res.result._source);
541+
} else {
542+
cb && cb(err);
543+
}
544+
});
545+
546+
return this;
547+
};
548+
549+
/**
550+
* Delete credentials of the specified <strategy> for the current user.
551+
*
552+
* @param strategy
553+
* @param options
554+
* @param cb
555+
* @returns {Kuzzle}
556+
*/
557+
Kuzzle.prototype.deleteMyCredentials = function (strategy, options, cb) {
558+
if (!cb && typeof options === 'function') {
559+
cb = options;
560+
options = null;
561+
}
562+
563+
this.query({controller: 'auth', action: 'deleteMyCredentials'}, {strategy: strategy}, options, typeof cb !== 'function' ? null : function(err, res) {
564+
if (!err) {
565+
cb && cb(null, res.result);
566+
} else {
567+
cb && cb(err);
568+
}
569+
});
570+
571+
return this;
572+
};
573+
574+
/**
575+
* Get credential information of the specified <strategy> for the current user.
576+
*
577+
* @param strategy
578+
* @param options
579+
* @param cb
580+
*/
581+
Kuzzle.prototype.getMyCredentials = function (strategy, options, cb) {
582+
if (!cb && typeof options === 'function') {
583+
cb = options;
584+
options = null;
585+
}
586+
587+
this.query({controller: 'auth', action: 'getMyCredentials'}, {strategy: strategy}, options, typeof cb !== 'function' ? null : function(err, res) {
588+
if (!err) {
589+
cb && cb(null, res.result);
590+
} else {
591+
cb && cb(err);
592+
}
593+
});
594+
};
595+
596+
/**
597+
* Update credentials of the specified <strategy> for the current user.
598+
*
599+
* @param strategy
600+
* @param credentals
601+
* @param options
602+
* @param cb
603+
* @returns {Kuzzle}
604+
*/
605+
Kuzzle.prototype.updateMyCredentials = function (strategy, credentials, options, cb) {
606+
if (!cb && typeof options === 'function') {
607+
cb = options;
608+
options = null;
609+
}
610+
611+
this.query({controller: 'auth', action: 'updateMyCredentials'}, {strategy: strategy, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
612+
if (!err) {
613+
cb && cb(null, res.result);
614+
} else {
615+
cb && cb(err);
616+
}
617+
});
618+
619+
return this;
620+
};
621+
622+
/**
623+
* Validate credentials of the specified <strategy> for the current user.
624+
*
625+
* @param strategy
626+
* @param credentials
627+
* @param options
628+
* @param cb
629+
*/
630+
Kuzzle.prototype.validateMyCredentials = function (strategy, credentials, options, cb) {
631+
if (!cb && typeof options === 'function') {
632+
cb = options;
633+
options = null;
634+
}
635+
636+
this.query({controller: 'auth', action: 'validateMyCredentials'}, {strategy: strategy, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
637+
if (!err) {
638+
cb && cb(null, res.result);
639+
} else {
640+
cb && cb(err);
641+
}
642+
});
643+
};
644+
523645
/**
524646
* Create a kuzzle index
525647
*

src/security/Security.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,197 @@ Security.prototype.getUserRights = function (userId, options, cb) {
751751
});
752752
};
753753

754+
/**
755+
* Create credentials of the specified <strategy> for the user <kuid>.
756+
*
757+
* @param strategy
758+
* @param kuid
759+
* @param credentials
760+
* @param options
761+
* @param cb
762+
* @returns {Security}
763+
*/
764+
Security.prototype.createCredentials = function (strategy, kuid, credentials, options, cb) {
765+
if (!cb && typeof options === 'function') {
766+
cb = options;
767+
options = null;
768+
}
769+
770+
this.kuzzle.query({controller: 'security', action: 'createCredentials'}, {_id: kuid, strategy: strategy, body: credentials}, options, function(err, res) {
771+
if (!err) {
772+
cb && cb(null, res.result._source);
773+
} else {
774+
cb && cb(err);
775+
}
776+
});
777+
778+
return this;
779+
};
780+
781+
/**
782+
* Delete credentials of the specified <strategy> for the user <kuid> .
783+
*
784+
* @param strategy
785+
* @param kuid
786+
* @param options
787+
* @param cb
788+
* @returns {Security}
789+
*/
790+
Security.prototype.deleteCredentials = function (strategy, kuid, options, cb) {
791+
if (!cb && typeof options === 'function') {
792+
cb = options;
793+
options = null;
794+
}
795+
796+
this.kuzzle.query({controller: 'security', action: 'deleteCredentials'}, {strategy: strategy, _id: kuid}, options, typeof cb !== 'function' ? null : function(err, res) {
797+
if (!err) {
798+
cb && cb(null, res.result);
799+
} else {
800+
cb && cb(err);
801+
}
802+
});
803+
804+
return this;
805+
};
806+
807+
/**
808+
* Retrieve a list of accepted fields per authentication strategy.
809+
*
810+
* @param options
811+
* @param cb
812+
*/
813+
Security.prototype.getAllCredentialFields = function (options, cb) {
814+
if (!cb && typeof options === 'function') {
815+
cb = options;
816+
options = null;
817+
}
818+
819+
this.kuzzle.query({controller: 'security', action: 'getAllCredentialFields'}, {}, options, typeof cb !== 'function' ? null : function(err, res) {
820+
if (!err) {
821+
cb && cb(null, res.result);
822+
} else {
823+
cb && cb(err);
824+
}
825+
});
826+
};
827+
828+
/**
829+
* Retrieve the list of accepted field names by the specified <strategy>.
830+
*
831+
* @param strategy
832+
* @param options
833+
* @param cb
834+
*/
835+
Security.prototype.getCredentialFields = function (strategy, options, cb) {
836+
if (!cb && typeof options === 'function') {
837+
cb = options;
838+
options = null;
839+
}
840+
841+
this.kuzzle.query({controller: 'security', action: 'getCredentialFields'}, {strategy: strategy}, options, typeof cb !== 'function' ? null : function(err, res) {
842+
if (!err) {
843+
cb && cb(null, res.result);
844+
} else {
845+
cb && cb(err);
846+
}
847+
});
848+
};
849+
850+
/**
851+
* Get credential information of the specified <strategy> for the user <kuid>.
852+
*
853+
* @param strategy
854+
* @param kuid
855+
* @param options
856+
* @param cb
857+
*/
858+
Security.prototype.getCredentials = function (strategy, kuid, options, cb) {
859+
if (!cb && typeof options === 'function') {
860+
cb = options;
861+
options = null;
862+
}
863+
864+
this.kuzzle.query({controller: 'security', action: 'getCredentials'}, {strategy: strategy, _id: kuid}, options, typeof cb !== 'function' ? null : function(err, res) {
865+
if (!err) {
866+
cb && cb(null, res.result);
867+
} else {
868+
cb && cb(err);
869+
}
870+
});
871+
};
872+
873+
/**
874+
* Check the existence of the specified <strategy>’s credentials for the user <kuid>.
875+
*
876+
* @param strategy
877+
* @param kuid
878+
* @param options
879+
* @param cb
880+
*/
881+
Security.prototype.hasCredentials = function (strategy, kuid, options, cb) {
882+
if (!cb && typeof options === 'function') {
883+
cb = options;
884+
options = null;
885+
}
886+
887+
this.kuzzle.query({controller: 'security', action: 'hasCredentials'}, {strategy: strategy, _id: kuid}, options, typeof cb !== 'function' ? null : function(err, res) {
888+
if (!err) {
889+
cb && cb(null, res.result);
890+
} else {
891+
cb && cb(err);
892+
}
893+
});
894+
};
895+
896+
/**
897+
* Updates credentials of the specified <strategy> for the user <kuid>.
898+
*
899+
* @param strategy
900+
* @param kuid
901+
* @param credentials
902+
* @param options
903+
* @param cb
904+
* @returns {Security}
905+
*/
906+
Security.prototype.updateCredentials = function (strategy, kuid, credentials, options, cb) {
907+
if (!cb && typeof options === 'function') {
908+
cb = options;
909+
options = null;
910+
}
911+
912+
this.kuzzle.query({controller: 'security', action: 'updateCredentials'}, {strategy: strategy, _id: kuid, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
913+
if (!err) {
914+
cb && cb(null, res.result);
915+
} else {
916+
cb && cb(err);
917+
}
918+
});
919+
920+
return this;
921+
};
922+
923+
/**
924+
* Validate credentials of the specified <strategy> for the user <kuid>.
925+
*
926+
* @param strategy
927+
* @param kuid
928+
* @param credentials
929+
* @param options
930+
* @param cb
931+
*/
932+
Security.prototype.validateCredentials = function (strategy, kuid, credentials, options, cb) {
933+
if (!cb && typeof options === 'function') {
934+
cb = options;
935+
options = null;
936+
}
937+
938+
this.kuzzle.query({controller: 'security', action: 'validateCredentials'}, {strategy: strategy, _id: kuid, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
939+
if (!err) {
940+
cb && cb(null, res.result);
941+
} else {
942+
cb && cb(err);
943+
}
944+
});
945+
};
946+
754947
module.exports = Security;

0 commit comments

Comments
 (0)