Code Monkey home page Code Monkey logo

kurvejs's Introduction

KurveJS

Kurve.JS is an unofficial, open source JavaScript / TypeScript library that aims to simplify two tasks:

  1. Easy authentication and authorization against Azure Active Directory - without navigating away from you web app for login or token requests.

  2. Easy access to the Microsoft Graph REST API.

How does it work?

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.

FAQ

Is this a supported library from Microsoft?

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.

Can I use/change this library?

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.

What if I find issues or want to contribute/help?

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

Which files do I need to run this?

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.

Release Notes

0.3.5:

  • New typed promises syntax supporting return and exception types

0.3.1:

  • Hotfix for the token expiration loop issue

0.3.0:

  • 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

0.2.0:

  • 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

kurvejs's People

Contributors

deltakosh avatar johnshew avatar matvelloso avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.