JavaScript OAuth SDK

The JavaScript OAuth SDK provides a quick and simple way to add LaunchKey authentication to your JavaScript application based on the popular OAuth 2.0 protocol.

Library

For the most recent stable version:

Before You Begin

Before you can begin using the LaunchKey API, you need a service. If you have not created a service yet, you can use our Getting Started Guide to create one.

This SDK uses OAuth to do its heavy lifting. This will require configuring your service. Please read OAuth Configuration for Services for instructions.

Getting Started

To get started, import the library within the <head>...</head> tags of your HTML.

Example

<script src="https://cdn.launchkey.com/oauth-js/lkoauth.min-latest.js"></script>

Initiating The Login Dialogue

To initiate the LaunchKey login dialogue, your end users will click a LaunchKey login button. The button will automatically be inserted by the JavaScript library wherever you place the following container within your HTML:

<!-- Paste this where you want your login button -->
<div id="lkLoginButton"></div>

Note

You may change the ID to whatever best suits your naming scheme as long as it's changed in the JavaScript call below.

Next, place the following JavaScript snippet immediately before the ending </body> tag in your HTML. The Service information you need can be found on your Service details page in your Dashboard.

<script type="text/javascript">
    LaunchKey.init({
        appKey: 1234567890,
        // Options are 'small', 'medium', and 'large' - default is 'large'
        size: 'large',
        // Options are 'mini', 'short', and 'full' - default is 'full'
        length: 'full',
        // Options are 'blue', 'light', and 'dark' - default is 'blue'
        color: 'blue',
        // Options are 'en', 'fr', 'it', 'de' and 'es' - default is 'en'
        lang: 'en',
        // The redirect URL a user should be directed to upon return from LaunchKey after logging in.
        // By default it will be the page sent from.
        // This must match the URL specified for OAuth domain in your dashboard.
        redirectUrl: location.protocol + '//' + location.host + window.location.pathname,
        //The id of the LaunchKey button.
        el: document.getElementById('lkLoginButton')
    });
</script>

Init Object Attributes

appKey:number 10 digit unique ID found in Service details page in your dashboard
size:string [small, medium, large] The size of the rendered button
length:string [mini, short, full] The visual format of the button
color:string [blue, light, dark] Login button color theme
lang:string [en, fr, it, de, es] Login button language
redirectUrl:string Location user will be redirected to after login (default is current page)
el:Element The login button DOM Element object

Login Response And Cookies

After a user successfully authenticates, two browser cookies are created:

LKlogin:Contains the OAuth access token of the user
LKuser:Contains the ID of the user. If you're setting a persistent session server-side or in a database, these two pieces of information are what you should store.

Log Out The User

To logout the user, you should eliminate the cookies that were created after login. This can be done by calling LaunchKey.logout() or by directing the user to the OAuth logout endpoint: https://oauth.launchkey.com/logout

Endpoint

https://oauth.launchkey.com/logout

Optional Parameters

close:boolean If true, window closes after signing out; default is false
redirect:string URL at your domain where you'd like the user to be redirected back to after sign out
access_token:string The access token of the user to be logged out
format:string [JSON, HTML] Response format

Example Using Endpoint

<a href="https://oauth.launchkey.com/logout?close=false&redirect=REDIRECT_PAGE_URL&access_token=USER_ACCESS_TOKEN&format=HTML">
    <button>Log Out</button>
</a>

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×