Javascript
This tutorial demonstrates how to add user login to a Javascript application using BlitzWare.
Last updated
Was this helpful?
This tutorial demonstrates how to add user login to a Javascript application using BlitzWare.
Last updated
Was this helpful?
You will need some details about your application to communicate with BlitzWare. You can get these details from the Application Settings section in the BlitzWare dashboard.
You need the Client ID.
A redirect URI is a URL in your application where BlitzWare redirects the user after they have authenticated. The redirect URI for your app must be added to the Redirect URIs list in your Application Settings under the Security tab. If this is not set, users will be unable to log in to the application and will get an error.
Reference the CDN:
Create a folder on your machine to house the application, then add an index.html
file to the root of the project. This HTML page will display a welcome message and have a "gated" section which requires the user to be authenticated before accessing. You can copy/paste the following content into the file. You will be adding more lines as you progress with this article.
Add the following content to the index.html
file you just created:
Finally, create a new file in the root of your application called app.js
. This will house the application-specific logic that you will create over the next few sections.
The folder structure so far should look like the following:
The BlitzWare Javascript SDK must be properly initialized with the information of the BlitzWare application created above. This must be initialized using your app's Client ID and Redirect URI.
The SDK gives you tools to quickly implement user authentication in your Javascript application, such as creating a login button using the login()
method from the BlitzWareAuth
class. Executing login()
redirects your users to the BlitzWare Universal Login Page, where BlitzWare can authenticate them. Upon successful authentication, BlitzWare will redirect your users back to your application.
The SDK helps you retrieve the profile information associated with logged-in users quickly, such as their name or profile picture, to personalize the user interface. The profile information is available through getUser
function exposed by the BlitzWareAuth
class.
You also need a way to log out. You can create a logout button using the logout()
method from the BlitzWareAuth
class. Executing logout()
clears the session and makes sure that the user can not access protected resources.
Take this app.js
file component as an example of how to use it:
That's it!
This article is based on the new SPA SDK available . You can reference the package from the CDN in the index.html
file by placing the script tags at the very bottom of the body
tag: