Skip to content

AutoLogin & Redirect Approach

Chris West edited this page Nov 20, 2020 · 15 revisions

URL structure

https://[dev]air.copperhillair.com/
GET Request

Query Params

t={base64 encoded login credentials JSON}

Example: (Login credentials JSON format)

{
  "user": "the-username",
  "pass": "the-password",
  "redirect": "/d/5uwRwmNMk/territory-map?orgId=2"
}

base-64 encoded by doing something similar to the following in the JS console while in AIR:

console.log(`${location.origin}/public/views/auto-login.html?t=` + btoa(JSON.stringify({
  user: "the-username",
  pass: "the-password",
  redirect: "/d/5uwRwmNMk/territory-map?orgId=2"
})));

This will result in a URL similar to this:

https://air.copperhillair.com/public/views/auto-login.html?t=eyAidXNlciI6ICJjcGhhaXIiLCAicGFzcyI6ICJjcGgxNTAwIiwgImxvZ291dCI6IHRydWUsICJyZWRpcmVjdCI6ICIlMkZkJTJGRU9ObWR5NmlrJTJGc2Vjb25kYXJ5JTNGb3JnSWQlM0QxJTI2a2lvc2slM0R0diIgfQ==

Bookmarklet

If you want to have a browser bookmark that will assist in creating the AutoLogin URL you can do the following:

  1. Create a new bookmark in your browser with the following as the URL:
    javascript:(function(e%2Cc)%7Bvar a%3Dnew XMLHttpRequest%3Ba.overrideMimeType("application%2Fjson")%3Ba.open("GET"%2C"https%3A%2F%2Fapi.github.com%2Fgists%2F"%2Be)%3Ba.onreadystatechange%3Dfunction()%7Bif(4%3D%3Da.readyState%26%26200%3D%3Da.status)%7Bvar d%3DJSON.parse(a.responseText)%2Cb%3Dd.files%5Bc%5D%3Bb%26%26b.content%3F(0%2Ceval)(b.content)%3Aconsole.error("There is no file with the following name in the specified GitHub Gist%3A  "%2Bc%2Cd)%7D%7D%3Ba.send(null)%7D)("e798e0477fc932c1636bfab62e003b4d"%2C"grafana-air-auto-login.js")%3Bvoid+0
    
  2. Save the bookmark (perhaps naming it something like AIR AutoLogin Link Creator).
  3. Navigate to the page that you want to show when automatically doing an auto login.
  4. Click the bookmark that you created.
    1. When prompted to enter the autologin username enter it and click OK.
    2. When prompted to enter the corresponding password enter that as well and click OK.
    3. Now you will see the URL that you can use to do an AutoLogin for the specified user.

The above bookmarklet works by running the code found in this Gist.

Clone this wiki locally