Git Product home page Git Product logo

jsconnectdotnet's Introduction

Vanilla jsConnect Client Library for .NET

This repository contains the files you need to use Vanilla's jsConnect with a .NET project.

Note: This library implements the version 3 protocol of jsConnect. If you need the legacy v2 protocol you can download the old release.

Requirements

This project depends on the following other libraries:

Installation

This project is distributed as sources. You will need to bring in the sources from the jsConnectDotNet folder and also the dependencies listed above.

Usage

To use jsConnect you will need to make a web page that gives information about the currently signed in user of your site. To do this you'll need the following information:

  • You will need the client ID and secret that you configured from within Vanilla's dashboard.
  • The currently signed in user or if there is no signed in user you'll also need that.

Basic Usage

To use the library you follow the basic process:

  1. Create an instance of the JsConnectV3 class.
  2. Assign your client ID and secret to configure it.
  3. Assign details of the current user.
  4. Call GenerateResponseLocation() to get the URL to redirect to.
  5. Perform a 302 redirect to the given location.
  6. If GenerateResponseLocation() throws an exception then you will need to display that to your users. This should only happen if there is a misconfiguration.

The following code snipped demonstrates the basic usage using

public class ExampleController: Controller {
        // In this example the "jwt" parameter is mapped to the "?jwt=..." query string.
        public ActionResult Index(string jwt) {
            jsc = new JsConnectV3();
            
            // First set your client ID and secret that you configured in your dashboard.
            jsc.SetSigningCredentials(ClientID, Secret);

            // Set the current user information.
            jsc.SetUniqueID("123");
            jsc.SetName("Username");
            jsc.SetEmail("[email protected]");
            jsc.SetPhotoUrl("https://example.com/avaar.jpg");
            jsc.SetUserField("customField", "Some custom field");
    
            try {
                // Generate the redirect URL and redirect.
                string redirectUrl = jsc.GenerateResponseLocation(jwt);
                new RedirectResult(url: redirectUrl, permanent: true);
            } catch (Exception ex) {
                // Display the exception in some custom way to your app.
                return new View(...);
            }
        }
    }

The method instantiates a JsConnectV3 object and sets it up. It then calls JsConnectV3::GenerateResponseLocation() with the jwt querystring parameter to process the request. You need to 302 redirect to that location.

If there is an exception you will need to display that on your page. Remember to escape the message.

Configuring Vanilla

Once you've made your authentication page you will need to add that URL to your jsConnect settings in Vanilla's dashboard. This is the authentication URL.

jsconnectdotnet's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsconnectdotnet's Issues

HttpUtility.UrlEncode() is unreliable

A client was reporting they he was having issues with jsConnect and after investigation:

There seem to be a problem with HttpUtility.UrlEncode().
See: https://github.com/vanilla/jsConnectdotNet/blob/master/Vanilla/jsconnect.cs#L185
From the documentation: https://msdn.microsoft.com/en-us/library/4fkewx0t(v=vs.110).aspx

You can encode a URL using with the UrlEncode method or the UrlPathEncode method. However, the methods return different results. The UrlEncode method converts each space character to a plus character (+). The UrlPathEncode method converts each space character into the string "%20", which represents a space in hexadecimal notation.

So the result from sigStr should be
email=email%40example.com&name=Freerk+Jelsma&uniqueid=1
and not
email=email%40example.com&name=Freerk%20Jelsma&uniqueid=1

http://stackoverflow.com/questions/602642/server-urlencode-vs-httputility-urlencode#answer-1148326 is reporting that this function is unreliable.

Timestamp uses DateTime.now?

Could this be using UTCnow instead (for us living outside GMT+0)? We got a timestamp-error when using this code on IIS. :)

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.