vanilla-aas
v0.1.2
Published
A package that integrates with AAS and CAMS. This all revolves around initially retrieving the **sid** and subsequently using that **sid** to authorize requests. The **sid** also gets stored in a cookie once logged in via AAS (blue screen login page)
Downloads
1
Readme
@census/vanilla-aas
A package that integrates with AAS and CAMS. This all revolves around initially retrieving the sid and subsequently using that sid to authorize requests. The sid also gets stored in a cookie once logged in via AAS (blue screen login page)
Features
- Login via AAS
- Retrieve CAMS permissions
- Logout via AAS
Dependencies
Depends on the server having implemented one of the following AAS auth packages:
- PHP Laravel census/laravel-aas implementation
Install or Update of this package
Warning: Developers, if you are installing this package to your laptop, you will need to run the commands below via the Bash CLI. Running them via Power Shell or cmd, may not yield the expected results. To get the Bash CLI you will need toinstall Git for Windows via SWG
Install
npm install git+https://git.econ.census.gov/solar/npm-packages/vanilla/aas
Update
npm update git+https://git.econ.census.gov/solar/npm-packages/vanilla/aas
Configuration
| Property | Type | Required | Value | Example | | ----------- | ----------- | --- | -- | -- | | baseUrl | string | yes| The location of the census/laravel-aas implementation | https://this.backend.census.gov/api | | authRedirectUrl | string | yes | Where to redirect the user once login has been completed. | https://this.frontend.census.gov/#/auth/ | | headers | object | no | Additional headers to add to our request | [ { 'key1: 'value1' }, { 'key2': 'value2' } ] |
Usage
Import Package and create instance
import CensusAas from '@census/vanilla-aas'
const censusAas = new CensusAas({
baseUrl: 'https://this.backend.census.gov/api',
authRedirectUrl: 'https://this.frontend.census.gov/auth',
headers: [
{ 'key1': 'value1' },
{ 'key2': 'value2' }
]
});
Vue.prototype.$censusAas = censusAas;
Get User Information
censusAas.getUser(function (err, response) {
if (err) {
console.error('Error occured', err)
return;
}
console.log('Success!', response);
});
Logout
censusAas.logout()
Response
{
"forbidden": <true | false >,
"user": {
"jbondid": "abcde012",
"logged": 1,
"sid": "12345678901234567890123456",
"firstName": "First",
"lastName": "Last",
"niceName": "First Last",
"division": "EAD",
"email": "[email protected]",
"phone": "301-763-XXXX",
"superuser": 1,
"office": "CENHQ-347uqie",
"cams": {
"groups": [
"Group 1",
"Group 2",
],
"roles": [
"Role 1",
"Role 2"
],
"permissions": [
"Permission 1",
"Permission 2"
]
},
"last_logged_at": "2021-09-27 20:21:23"
}
}
Examples
Vue
Example: Solar / Boilerplates / vue2-vuetify-boilerplate · GitLab (census.gov)
.env
VUE_APP_AUTH_API_BASE_URL="https://this.backend.census.gov/api"
VUE_APP_AUTH_REDIRECT=https://this.frontend.census.gov/#/auth/
main.js
import Vue from 'vue'
import router from './router'
import App from './App.vue'
// AAS connectivity
import CensusAas from '@census/vanilla-aas'
const censusAas = new CensusAas({
baseUrl: process.env.VUE_APP_AUTH_API_BASE_URL,
authRedirectUrl: process.env.VUE_APP_AUTH_REDIRECT,
headers: [
{ 'key1': 'value1' },
{ 'key2': 'value2' }
]
});
Vue.prototype.$censusAas = censusAas;
new Vue({
render: h => h(App),
router,
store: store,
async beforeCreate() {
const self = this
censusAas.getUser(function (err, response) {
if (err) {
console.error(err);
return
}
// response contains user
console.log(response)
});
},
}).$mount('#app')
router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import Cookies from 'js-cookie'
Vue.use(Router);
let router = new Router({
routes: [
//AUTH
{
path: '/auth/:sid',
redirect: to => {
const {
query
} = to;
Cookies.set('sid', to.params.sid);
return {
path: '/',
query: query
}
}
}
]
})
export default router;
Developpers
To install a specific branch, use the following command (where <branch_name>
is the name of the branch you want to pull:
npm install "git+https://git.econ.census.gov/solar/npm-packages/vanilla/aas#<branch_name>"