computer solutions: JSON Web Token Tutorial: An Example in Laravel and AngularJS

  • It comprises a compact and URL-safe JSON object, which is cryptographically signed to verify its authenticity, and which can also be encrypted if the payload contains sensitive information.Because of it’s compact structure, JWT is usually used in HTTPheaders or URL query parameters.A JWT is represented as a sequence of base64url encoded values that are separated by period characters.JSON Web Token example:The header contains the metadata for the token and it minimally contains the type of signature and the encryption algorithm.
  • This JWT Header declares that the encoded object is a JSON Web Token, and that it is signed using the HMAC SHA-256 algorithm.Once this is base64 encoded, we have the first part of our JWT.In the context of JWT, a claim can be defined as a statement about an entity (typically, the user), as well as additional meta data about the token itself.
  • However, if we want to add an additional layer of protection, we can encrypt the JWT payload itself using the JSON Web Encryption (JWE) specification.Of course, if we want to avoid the additional overhead of using JWE, another option is to simply keep sensitive information in our database, and use our token for additional API calls to the server whenever we need to access sensitive data.Before we can see all the benefits of using token authentication, we have to look at the way authentication has been done in the past.Because the HTTP protocol is stateless, there needs to be a mechanism for storing user information and a way to authenticate the user on every subsequent request after login.
  • We can easily use the same token for fetching a secure resource from a domain other than the one we are logged in to.A browser or mobile client makes a request to the authentication server containing user login information.
  • The only thing we have to do is calculate the HMAC SHA-256 to validate the token and parse its content.In this tutorial I am going to demonstrate how to implement the basic authentication using JSON Web Tokens in two popular web technologies: Laravel 5 for the backend code and AngularJS for the frontend Single Page Application (SPA) example.

Continue reading “computer solutions: JSON Web Token Tutorial: An Example in Laravel and AngularJS”

DHTMLX Gantt Chart Usage with Angular JS 2 Framework

  • To add data loading to our angular gantt chart, we are going to add task and link services.
  • Angular services can be injected using Dependency Injection mechanism and include data, function or some features necessary for your application.
  • We’re going to create a data service that we’ll use to provide our gantt chart with tasks.
  • So, our component can use that services to get tasks and links.
  • Also here we call our services to get function and then are waiting for response to put data to gantt.

DHTMLX Blog – Rich JavaScript Library and UI Widgets – News, Tips, Updates
Continue reading “DHTMLX Gantt Chart Usage with Angular JS 2 Framework”

How to use AngularJS and Laravel Blade together

  • In this article I will show you how to use AngularJS and Laravel Blade together.
  • When it comes to making AngularJS and Laravel Blade work together, there is only one real problem.
  • Both AngularJS and Laravel Blade use double curly brackets for opening and closing tags.
  • The solution for making AngularJS and Laravel Blade work together is simple.
  • Example code would be:

    You can now freely use %% for AngularJS and the usual {{ and }} for Laravel Blade!

In this article we will have a look at how to use AngularJS and Laravel Blade together by changing the opening and closing tags of AngularJS
Continue reading “How to use AngularJS and Laravel Blade together”

Angular testing made easy – Clarity Design System – Medium

Angular testing made easy @EudesPV  #AngularJS #Nodejs #JavaScript #Testing

  • So what’s the most efficient way to centralize that boilerplate, so that your actual spec files can focus on the unit tests themselves?This article will show you a neat solution to this problem, using two little-known features: Jasmine’s user context and Typescript’s ability to type this.
  • There are two main advantages to this approach over local variables: it helps fight the memory leaks that keep creeping up on large projects’ tests, and it also offers a very easy way to have your beforeEach and it in two different files, which is much harder to set up with local variables.CAUTION: We are using a plain function() {} here, rather than the very useful () = {} arrow notation from Typescript.
  • One of the recommended patterns (and the one we use the most, by far, in Clarity) is to use a “test host” component which includes the actual component to test in its template:This example makes a few assumptions to keep it simple: the templates are all inline or inlined at build time so we don’t need to MyUserComponent doesn’t depend on other components, … Feel free to adapt to your specific use case.Introducing the TestContextIf we want to extract all the boilerplate into a separate file, we need to decide what the type of the user context passed around by Jasmine should be.
  • The one difference is that we’re getting the tested directive through the injector, rather than componentInstance, once again to be able handle attribute directives and components at the same time.The final spec fileLet’s remove all the boilerplate from the user component’s spec file and use our brand new context:It’s now entirely comprised of the unit tests, no distractions or verbose setup to go through.
  • That’s a win!To improve this further, you could easily:include the setup() call at the root of the tests to have it always be available,allow passing extra directives to declare or modules to import, in case your component depends on other ones,add additional shortcuts to the TestContext interface,throw explicit errors when trying to test with a host component that does not contain the directive,…In our case, for instance, we have a shortcut to get providers from the tested element’s injector.

If you’re here, you have probably already read the Angular documentation on testing, and maybe have written a few tests for your own project. If you have not, I can only suggest you do so, because…
Continue reading “Angular testing made easy – Clarity Design System – Medium”

angular-state-loader

  • Add and dependencies to your html:

    Add Angular module as dependency to your app:

    To use the default Loader Template, you need Material Icons which can be included via the google CDN:

    If you do not want to use material icons, always use a custom template like explained below.

  • ###Custom Loader at runtime If you want to have a custom loader (or do not want to use material-icons), just make sure your -tag is not empty:

    ###Change default template If you want to change the default template for all loaders, you can use the stateLoaderProvider in your config.

  • You can either configure a template url with setTemplateUrl:

    ###delay By default, the loader will show up after 100ms of loading time and will stay until all of the state’s promises are resolved.

  • This delay can be changed with the property (in ms):

    The above loader will show up if resolving the state’s promises is taking longer than 10 seconds.

  • At last, here is a full example of how it can be used fully customized:

    The above loader will only show if transitioning from state “bakery” to state “bakery.muffins” after 500ms loading time, showing a custom message.

Loading Spinner for UI Router (AngularJS) that is shown while loading a states resolves. Can be restricted to specific state transitions. Including the optional parameters force-show and delay + the possibility to show a custom loader.
Continue reading “angular-state-loader”

GitHub

  • Add and dependencies to your html:

    Add Angular module as dependency to your app:

    To use the default Loader Template, you need Material Icons which can be included via the google CDN:

    If you do not want to use material icons, always use a custom template like explained below.

  • ###Custom Loader at runtime If you want to have a custom loader (or do not want to use material-icons), just make sure your -tag is not empty:

    ###Change default template If you want to change the default template for all loaders, you can use the stateLoaderProvider in your config.

  • You can either configure a template url with setTemplateUrl:

    ###delay By default, the loader will show up after 100ms of loading time and will stay until all of the state’s promises are resolved.

  • This delay can be changed with the property (in ms):

    The above loader will show up if resolving the state’s promises is taking longer than 10 seconds.

  • At last, here is a full example of how it can be used fully customized:

    The above loader will only show if transitioning from state “bakery” to state “bakery.muffins” after 500ms loading time, showing a custom message.

angular-state-loader – Loading Spinner for UI Router (AngularJS) that is shown while loading a state’s promises resolve. Can be restricted to specific state transitions. Including the optional parameters force-show and delay + the possibility to show a custom loader.
Continue reading “GitHub”