How to use bearerToken method in argos

Best JavaScript code snippet using argos

bearertoken-unit-test.js

Source:bearertoken-unit-test.js Github

copy

Full Screen

1// bearertoken-unit-test.js2//3// Test that the BearerToken class works as expected4//5// Copyright 2018 E14N <https://e14n.com>6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11// http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18"use strict";19var fs = require("fs");20var path = require("path");21var vows = require("vows");22var assert = require("assert");23var databank = require("databank");24var Databank = databank.Databank;25var DatabankObject = databank.DatabankObject;26var _ = require("lodash");27var tc = _.clone(require("./config.json"));28var client = tc.clients[0];29var user = tc.users[2];30var SCOPE = "read";31vows.describe("BearerToken data type")32 .addBatch({33 "When we load the module": {34 topic: function() {35 try {36 var mod = require("../lib/model/bearertoken");37 var BearerToken = mod.BearerToken;38 this.callback(null, BearerToken);39 } catch (err) {40 this.callback(err);41 }42 return undefined;43 },44 "it works": function(err, BearerToken) {45 assert.ifError(err);46 assert.isFunction(BearerToken);47 },48 "it has a create() method": function(err, BearerToken) {49 assert.ifError(err);50 assert.isFunction(BearerToken);51 assert.isFunction(BearerToken.create);52 },53 "it has a get() method": function(err, BearerToken) {54 assert.ifError(err);55 assert.isFunction(BearerToken);56 assert.isFunction(BearerToken.get);57 },58 "it has a save() method": function(err, BearerToken) {59 assert.ifError(err);60 assert.isFunction(BearerToken);61 assert.isFunction(BearerToken.prototype.save);62 },63 "and we open a database": {64 topic: function(BearerToken) {65 var callback = this.callback;66 var schema = {};67 schema[BearerToken.type] = BearerToken.schema;68 var params = _.extend({schema: schema}, tc.params);69 var bank = Databank.get(tc.driver, params);70 bank.connect(params, function(err) {71 if (err) {72 callback(err);73 } else {74 DatabankObject.bank = bank;75 callback(null, bank);76 }77 });78 },79 "it works": function(err, bank) {80 assert.ifError(err);81 assert.isObject(bank);82 },83 "teardown": function(bank) {84 bank.disconnect(this.callback);85 },86 "and we create a new user token": {87 topic: function(bank, BearerToken) {88 var props = {89 "nickname": user.nickname,90 "client_id": client.client_id,91 "scope": SCOPE92 };93 BearerToken.create(props, this.callback);94 },95 "it works": function(err, bt) {96 assert.ifError(err);97 assert.isObject(bt);98 assert.isString(bt.token);99 assert.isString(bt.created);100 assert.equal(bt.nickname, user.nickname);101 assert.equal(bt.client_id, client.client_id);102 assert.equal(bt.scope, SCOPE);103 },104 "and we get the same token out": {105 topic: function(created, bank, BearerToken) {106 var callback = this.callback;107 BearerToken.get(created.token, function(err, gotten) {108 if (err) {109 callback(err);110 } else {111 callback(null, gotten, created);112 }113 });114 },115 "it works": function(err, gotten, created) {116 assert.ifError(err);117 assert.isObject(gotten);118 assert.isObject(created);119 assert.equal(gotten.token, created.token);120 assert.isString(gotten.created);121 assert.equal(gotten.nickname, user.nickname);122 assert.equal(gotten.client_id, client.client_id);123 assert.equal(gotten.scope, SCOPE);124 }125 }126 },127 "and we create a new client token": {128 topic: function(bank, BearerToken) {129 var props = {130 "client_id": client.client_id131 };132 BearerToken.create(props, this.callback);133 },134 "it works": function(err, bt) {135 assert.ifError(err);136 assert.isObject(bt);137 assert.isString(bt.token);138 assert.isString(bt.created);139 assert.ok(!bt.nickname);140 assert.equal(bt.client_id, client.client_id);141 assert.ok(!bt.scope);142 },143 "and we get the same token out": {144 topic: function(created, bank, BearerToken) {145 var callback = this.callback;146 BearerToken.get(created.token, function(err, gotten) {147 if (err) {148 callback(err);149 } else {150 callback(null, gotten, created);151 }152 });153 },154 "it works": function(err, gotten, created) {155 assert.ifError(err);156 assert.isObject(gotten);157 assert.isObject(created);158 assert.equal(gotten.token, created.token);159 assert.isString(gotten.created);160 assert.ok(!gotten.nickname);161 assert.equal(gotten.client_id, client.client_id);162 assert.ok(!gotten.scope);163 }164 }165 },166 "and we create a defined user token": {167 topic: function(bank, BearerToken) {168 var props = {169 "token": "UNITTESTBEARERTOKEN1",170 "nickname": user.nickname,171 "client_id": client.client_id,172 "scope": SCOPE173 };174 BearerToken.create(props, this.callback);175 return undefined;176 },177 "it works": function(err, bt) {178 assert.ifError(err);179 assert.isObject(bt);180 assert.isString(bt.created);181 assert.equal(bt.token, "UNITTESTBEARERTOKEN1");182 },183 "and we get the same token out": {184 topic: function(created, bank, BearerToken) {185 var callback = this.callback;186 BearerToken.get(created.token, function(err, gotten) {187 if (err) {188 callback(err);189 } else {190 callback(null, gotten, created);191 }192 });193 },194 "it works": function(err, gotten, created) {195 assert.ifError(err);196 assert.isObject(gotten);197 assert.isObject(created);198 assert.equal(gotten.token, created.token);199 assert.isString(gotten.created);200 assert.equal(gotten.nickname, created.nickname);201 assert.equal(gotten.client_id, client.client_id);202 assert.equal(gotten.scope, created.scope);203 }204 }205 }206 }207 }208 })...

Full Screen

Full Screen

APIManager.js

Source:APIManager.js Github

copy

Full Screen

1import {base_url, router} from './URLProvider';2import apisauce from 'apisauce';3import {4 getBearToken,5 getDateForTeam,6 getUserName,7} from '../Utils/HelperService';8import {getSTime, getSTimeForPost} from '../Utils/extension';9import * as NavigationService from './..//Navigators/NavigationService';10import Constants from '../Config/Constants';11const api = apisauce.create({12 baseURL: base_url,13 headers: {14 // Accept: 'application/json',15 // 'Content-Type': 'application/json',16 'Cache-Control': 'no-cache',17 },18 timeout: 30000,19});20function checkLoginStatus(res) {21 if (res.status === 401) {22 NavigationService.navigate('Login', {23 tokenExpired: true,24 });25 }26}27async function getProfile() {28 const bearerToken = await getBearToken();29 api.setHeader('Authorization', bearerToken);30 return api.get(router.currentUser);31}32async function getColleague(searchString, date) {33 const query = {34 'request.query': searchString,35 'request.date': getSTime(date),36 };37 const bearerToken = await getBearToken();38 api.setHeader('Authorization', bearerToken);39 return api.get(router.colleague, query);40}41async function getMyReservation(searchString) {42 const bearerToken = await getBearToken();43 api.setHeader('Authorization', bearerToken);44 return api.get(router.reservations);45}46// TODO -> change endpoint47async function getMyLunch() {48 const bearerToken = await getBearToken();49 api.setHeader('Authorization', bearerToken);50 return api.get(router.reservations);51}52async function getLocations(searchString) {53 const bearerToken = await getBearToken();54 api.setHeader('Authorization', bearerToken);55 return api.get(router.locations);56}57async function getCheckInInfo(seatId) {58 const bearerToken = await getBearToken();59 api.setHeader('Authorization', bearerToken);60 return api.get(`${router.checkinInfo}?seatId=${seatId}`);61}62async function getFacilities() {63 const bearerToken = await getBearToken();64 api.setHeader('Authorization', bearerToken);65 return api.get(router.facilities);66}67async function getAreas(locationId, startDate, endDate) {68 var query;69 if (startDate == null) {70 query = {71 'request.locationId': locationId,72 };73 } else {74 query = {75 'request.locationId': locationId,76 'request.startDate': getSTime(startDate),77 'request.endDate': getSTime(endDate),78 };79 }80 const bearerToken = await getBearToken();81 api.setHeader('Authorization', bearerToken);82 return api.get(router.areas, query);83}84async function getLunches(locationId, date) {85 const query = {86 fromDate: getSTime(date),87 toDate: getSTime(date),88 LocationId: locationId,89 };90 const bearerToken = await getBearToken();91 api.setHeader('Authorization', bearerToken);92 return api.get('/Reservations/PreBookingInfo', query);93}94async function getSeats(locationId) {95 const bearerToken = await getBearToken();96 api.setHeader('Authorization', bearerToken);97 return api.get(`/Admin/Areas/${locationId}/Seats`);98}99async function getReservationLocation(areaId, date = new Date()) {100 var query;101 query = {102 areaId: areaId,103 startDate: `${getSTime(date)}T00:00:00.000Z`,104 endDate: `${getSTime(date)}T23:59:59.999Z`,105 };106 const bearerToken = await getBearToken();107 api.setHeader('Authorization', bearerToken);108 return api.get(router.reservationLocations, query);109}110async function getImage(areaId) {111 const query = {v: getSTime(new Date())};112 const bearerToken = await getBearToken();113 api.setHeader('Authorization', bearerToken);114 return api.get(`${router.areas}/${areaId}${router.image}`, query);115 // return fetch(imageUrl, {116 // method: 'GET',117 // headers: {118 // Authorization: bearerToken,119 // },120 // });121}122async function checkInAtHome(dates) {123 const bearerToken = await getBearToken();124 api.setHeader('Authorization', bearerToken);125 // const query = {date: getSTimeForPost(new Date())};126 // return api.post(`${router.reservations}/AtHome/CheckIn`, query);127 let query;128 if (dates == null) {129 query = {Dates: [getSTimeForPost(new Date())]};130 } else {131 query = {Dates: dates};132 }133 return api.post(`${router.reservations}/AtHome`, query);134}135async function quickCheckIn(data) {136 const bearerToken = await getBearToken();137 api.setHeader('Authorization', bearerToken);138 return api.post(`${router.reservations}/QuickCheckIn`, data);139}140async function checkInReservation(reservationId) {141 const bearerToken = await getBearToken();142 api.setHeader('Authorization', bearerToken);143 return api.put(`${router.reservations}/${reservationId}${router.checkIn}`);144}145async function checkInGuest(guestId) {146 const bearerToken = await getBearToken();147 api.setHeader('Authorization', bearerToken);148 return api.put(149 `${router.reservations}/${router.guests}/${guestId}${router.checkIn}`,150 );151}152async function deleteReservation(reservation) {153 const bearerToken = await getBearToken();154 api.setHeader('Authorization', bearerToken);155 if (reservation.Area != null) {156 return api.delete(`${router.reservations}/${reservation.Id}`);157 } else {158 return api.delete(`${router.reservations}/AtHome/${reservation.Id}`);159 }160}161async function deleteGuest(guestId) {162 const bearerToken = await getBearToken();163 api.setHeader('Authorization', bearerToken);164 return api.delete(`${router.reservations}/${router.guests}/${guestId}`);165}166async function createReservation(body) {167 const bearerToken = await getBearToken();168 api.setHeader('Authorization', bearerToken);169 return api.post(router.reservations, body);170}171async function createGuest(body) {172 const bearerToken = await getBearToken();173 api.setHeader('Authorization', bearerToken);174 return api.post(`${router.reservations}/${router.guests}`, body);175}176async function updateReservation(reservationId, body) {177 const bearerToken = await getBearToken();178 api.setHeader('Authorization', bearerToken);179 return api.put(`${router.reservations}/${reservationId}`, body);180}181async function updateGuest(guestId, body) {182 const bearerToken = await getBearToken();183 api.setHeader('Authorization', bearerToken);184 return api.put(`${router.reservations}/${router.guests}/${guestId}`, body);185}186async function addTeamMember(ColleagueEmail) {187 const bearerToken = await getBearToken();188 api.setHeader('Authorization', bearerToken);189 return api.post(router.myTeam, {ColleagueEmail});190}191async function getTeamList() {192 // const query = {date: getSTime(new Date())};193 let date = await getDateForTeam();194 if (date == null) {195 date = getSTime(new Date());196 }197 const query = {date: date};198 const bearerToken = await getBearToken();199 api.setHeader('Authorization', bearerToken);200 return api.get(router.myTeam, query);201}202async function deleteTeamMember(id) {203 const bearerToken = await getBearToken();204 api.setHeader('Authorization', bearerToken);205 return api.delete(`${router.myTeam}/${id}`);206}207async function refreshToken() {208 const email = await getUserName();209 const newApi = apisauce.create({210 baseURL: 'https://login.microsoftonline.com/common/oauth2',211 headers: {212 // Accept: 'application/json',213 // 'Content-Type': 'application/json',214 'Cache-Control': 'no-cache',215 },216 timeout: 30000,217 });218 const query = {219 client_id: '8eb0134e-ee8f-4744-a3b3-6c01e2b5bb7c',220 response_type: 'token',221 redirect_uri: 'https%3A%2F%2Fportlr-bookings-test.azurewebsites.net%2F',222 scope: 'User.ReadBasic.All+User.Read',223 nonce: '12bfd3a1-e475-4a29-be6d-88358932c9be',224 state: 'abcd',225 login_hint: email,226 };227 return newApi.get('authorize', query);228}229function getRefreshTokenUrl() {230 const rad = '94c125e8-878d-4efe-a2bc-9051ccbcdc98';231 return `https://login.microsoftonline.com/common/oauth2/authorize?client_id=${Constants.credentials.client_id}&response_type=id_token&redirect_uri=https%3A%2F%2Fportlr-bookings-test.azurewebsites.net%2F&nonce=${rad}&state=${rad}`;232}233export const apiManager = {234 refreshToken,235 getRefreshTokenUrl,236 getProfile,237 getColleague,238 getMyReservation,239 getMyLunch,240 getLocations,241 getFacilities,242 getAreas,243 getImage,244 checkLoginStatus,245 checkInReservation,246 getReservationLocation,247 deleteReservation,248 createReservation,249 updateReservation,250 addTeamMember,251 getTeamList,252 deleteTeamMember,253 checkInAtHome,254 checkInGuest,255 deleteGuest,256 createGuest,257 updateGuest,258 getLunches,259 getSeats,260 getCheckInInfo,261 quickCheckIn,...

Full Screen

Full Screen

bearer-token.service.ts

Source:bearer-token.service.ts Github

copy

Full Screen

...27 }28 public resetBearerToken(){29 this._BearerToken = undefined;30 }31 public set bearerToken(token: BearerToken) {32 this._BearerToken = token;33 }34 public get bearerToken(): BearerToken {35 if(this._BearerToken)36 return this._BearerToken;37 else38 return new BearerToken();39 }40 public isBearerTokenSet(): boolean {41 return (this.bearerToken.access_token != undefined);42 }43 // returns undefined if the user isn't logged in44 public get getUserRole(): UserRoleEnum | undefined {45 if(!this.isBearerTokenSet() || this.bearerToken.access_token == null){46 return undefined;47 }48 let decodedToken = jwtDecode(this.bearerToken.access_token);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosSDK = require('argos-sdk');2var bearerToken = argosSDK.bearerToken;3var token = bearerToken('your token here');4token.getToken().then(function (token) {5 console.log(token);6});7[MIT](LICENSE)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run argos automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful