Kurve.JS is an unofficial, open source JavaScript / TypeScript library that aims to simplify two tasks:
-
Easy authentication and authorization against Azure Active Directory - without navigating away from you web app for login or token requests.
-
Easy access to the Microsoft Graph REST API.
Reference the JavaScript file from your HTML page:
<script src="Kurve.min.js"></script>
Alternatively you can just reference the script from our CDN:
<script src="https://kurvejs.blob.core.windows.net/dist/kurve.min-0.3.5.js"></script>
The identity and graph classes can work independently or together. For example, you may have authenticated and retrieved an access token from somewhere else and only give it to the graph library, or you can use the identity library for authentication.
//Option 1: We already have an access token obtained from another library:
var graph = new Kurve.Graph({ defaultAccessToken: token });
//Option 2: Automatically linking to the Identity object
var identity = new Kurve.Identity(
"your_client_id",
"your_redirect_url");
var identity.login(function (error) {
var graph = new Kurve.Graph({ identity: identity });
}
And then we can start using the graph objects:
//Get the top 5 users
graph.users((function(users, error) {
getUsersCallback(users, error);
}), "$top=5");
//Get the top 5 users with Promises
graph.usersAsync("$top=5").then((function(users) {
getUsersCallback(users, null);
//Get user "me" and then the user's e-mails from Exchange Online:
graph.meAsync().then(function(user) {
var result = "User:" + user.data.displayName;
user.messagesAsync(“$top=5”).then(function(messages) {
messagesCallback(messages);
});
});
function messagesCallback(messages) {
if (messages.nextLink){
//Check for messages and see if there's
//another page to be loaded
messages.nextLink().then(messagesCallback);
}
}
Just like in the graph example, with identity it is also possible to choose callbacks or Promises syntax:
var identity = new Kurve.Identity(
"your_clientid",
"your_redirect_url");
identity.login(function(error) {
if (!error){
//login worked
}
identity.getAccessToken("https://graph.microsoft.com",(function (token,error) {
if (!error){
//token received
}
});
});
If you prefer the Promises syntax, you can also do it that way:
var identity = new Kurve.Identity(
"your_clientid",
"your_redirect_url");
identity.loginAsync().then(function() {
identity.getAccessTokenAsync("https://graph.microsoft.com").then(function (token) {
//token received
});
});
The sample index.html and app.js files show how to wire and use it.
No it is not. This is an open source project built unofficially. If you are looking for a supported APIs we encourage you to directly call Microsoft's Graph REST APIs.
You are free to take the code, change and use it any way you want it. But please be advised this code isn't supported.
You are free to send us your feedback at this Github repo, send pull requests, etc. But please don't expect this to work as an official support channel
At minimum you need the KurveGraph.js and Promises.js, and optionally KurveIdentity.js + login.html. You may use the TypeScript libraries and reuse some of the sample app code (index.html and app.js) for reference.
- New typed promises syntax supporting return and exception types
- Hotfix for the token expiration loop issue
- Better type support for all returned types in callbacks
- Standardized return entities and collections into .data for all related properties returned from the graph so we differentiate the model data from action methods more easily
- Minification and unification of the library into a single file
- No need for tenant ID anymore
- Improved error handling, all error returns are now coming into the Kurve.Error class format
- Additional graph methods, like reading groups, user profile's photos, user manager and direct reports