# How to initialize 'angularAuth0Provider' without static variables with Angularjs(1.6.4)

**URL:** <https://community.auth0.com/t/how-to-initialize-angularauth0provider-without-static-variables-with-angularjs-1-6-4/9263>\
**Category:** Get Help\
**Tags:** credential-managemen, angularauth0provider, appjs, heroku, angularjs\
**Created:** [January 23, 2018, 4:43am UTC](https://community.auth0.com/t/how-to-initialize-angularauth0provider-without-static-variables-with-angularjs-1-6-4/9263 "2018-01-23T04:43:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiramgm](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@hiramgm](https://community.auth0.com/u/hiramgm)\
**Post date:** [January 23, 2018, 4:43am UTC](https://community.auth0.com/t/how-to-initialize-angularauth0provider-without-static-variables-with-angularjs-1-6-4/9263/1 "2018-01-23T04:43:45Z")

</div>

My application is in Heroku, it’s developed in Angularjs (1.6.4), I have some varibles in Heroku, I can access them through the server, I made an API to return the varibles by means of a request with the GET method, everything that works , the problem is when I call the service from the app.js, which is where ‘angularAuth0Provider’ is initialized, my question is where can I initialize this method in such a way that before initializing it?, I will first make an HTTP request to the server to return the data and do not change them directly in the code, but according to the internet you can’t use services in APP.JS, they say that you do it in APP.RUN.JS but I need that data to be able to get to that file, if you don’t have them Error initializing the application.

CODE OF APP.JS  
(function() {  
“use strict”;

angular  
.module(“app”,  
“auth0.auth0”,  
“ui.router”,  
“ngMaterial”,  
“ngMessages”,  
“datePicker”,  
“angular-loading-bar”,  
“ngStorage”  
])  
.config(config);

config.$inject =  
“$stateProvider”,  
“$locationProvider”,  
“$urlRouterProvider”,  
“angularAuth0Provider”  
];

## function config( $stateProvider, $locationProvider, $urlRouterProvider, angularAuth0Provider ) { $stateProvider .state(“home”, { url: “/”, controller: “HomeController”, templateUrl: “app/views/project/home.html”, controllerAs: “vm” }) .state(“worklogs”, { url: “/work-log”, controller: “WorkLogController”, name: “worklog”, templateUrl: “app/views/project/work-log/work-log.html”, controllerAs: “vm” }) .state(“callback”, { url: “/callback”, controller: “CallbackController”, templateUrl: “app/callback/callback.html”, controllerAs: “vm” });

## I WANT TO DO THE REQUEST HERE

THEN…  
// Initialization for the angular-auth0 library WITH RESULTS OF THE REQUEST  
angularAuth0Provider.init({  
clientID: “----------”,  
domain: “-----------------”,  
responseType: “token id\_token”,  
audience: “--------------”,  
redirectUri: “----------------”,  
scope: “openid”  
});  
$urlRouterProvider.otherwise(“/”);  
$locationProvider.hashPrefix(“”);  
/// Comment out the line below to run the app  
// without HTML5 mode (will use hashes in routes)  
$locationProvider.html5Mode(true);  
}  
})();

CODE OF SERVER.JS  
const express = require(“express”);  
const app = express();  
const path = require(“path”);  
const PORT = process.env.PORT || 5000;  
const nforce = require(“nforce”);  
const http = require(“http”);  
var localStorage = require(“localStorage”);  
var cors = require(“cors”);  
var oauth;  
var token = “”;  
var CLIENT\_ID = process.env.CLIENT\_ID;  
var CLIENT\_SECRET = process.env.CLIENT\_SECRET;  
var USERNAME = process.env.USERNAME;  
var PASSWORD = process.env.PASSWORD;  
var BASEURL = process.env.BASEURL;  
var SECURITYTOKEN = process.env.SECURITYTOKEN;  
var REDIRECT\_URL = process.env.REDIRECT\_URL;  
var audienceauth0 = process.env.audienceauth0;  
var clientIDauth0 = process.env.clientIDauth0;  
var domainauth0 = process.env.domainauth0;  
var redirectUriauth0 = process.env.redirectUriauth0;  
var responseTypeauth0 = process.env.responseTypeauth0;  
var scopeauth0 = process.env.scopeauth0;  
var MODE = “”,  
ENVIRONMENT = “”,  
APIVERSION = “”;  
const server = app.listen(PORT, () =\> console.log(`Listening on ${PORT}`));  
if (process.env.MODE != null) {  
MODE = process.env.MODE;  
}

if (process.env.ENVIRONMENT != null) {  
ENVIRONMENT = process.env.ENVIRONMENT;  
}

if (process.env.APIVERSION != null) {  
APIVERSION = process.env.APIVERSION;  
}  
const org = nforce.createConnection({  
clientId: CLIENT\_ID,  
clientSecret: CLIENT\_SECRET,  
redirectUri: REDIRECT\_URL,  
apiVersion: APIVERSION, // optional, defaults to current salesforce API version  
environment: ENVIRONMENT, // optional, salesforce ‘sandbox’ or ‘production’, production default  
mode: MODE, // optional, ‘single’ or ‘multi’ user mode, multi default  
username: USERNAME,  
password: PASSWORD,  
securityToken: SECURITYTOKEN  
});

app.use(“/”, express.static(\_\_dirname + “/”));

app.get(“/”, function(req, res) {  
res.sendFile(path.join(\_\_dirname + “/index.html”));  
});

app.get(“/callback”, function(req, res) {  
res.sendFile(path.join(\_\_dirname + “/index.html”));  
});

## app.get(“/work-log”, function(req, res) { res.sendFile(path.join(\_\_dirname + “/index.html”)); }); app.get(“/api/salesforce/baseurl”, function(req, res) { return res.json({ BASEURL: BASEURL }); });

## API

app.get(“/api/auth0/data”, function(req, res) {  
return res.json({  
audienceauth0: audienceauth0,  
clientIDauth0: clientIDauth0,  
domainauth0: domainauth0,  
redirectUriauth0: redirectUriauth0,  
responseTypeauth0: responseTypeauth0,  
scopeauth0: scopeauth0  
});  
});

app.get(“/api/salesforce/token”, function(req, res) {  
org.authenticate({}, function(err, resp) {  
if (!err) {  
oauth = resp;  
token = resp.access\_token;  
} else {  
console.log(err);  
}  
});  
return res.json({ TOKEN: token });  
});

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [December 14, 2018, 6:04pm UTC](https://community.auth0.com/t/how-to-initialize-angularauth0provider-without-static-variables-with-angularjs-1-6-4/9263/2 "2018-12-14T18:04:57Z")

</div>

As it has been more than a few months since this topic was opened, and there has been no reply or further information provided as to the existence of the issue, we are closing this topic. Please don’t hesitate to create a new topic if this issue is still present, we would be happy to work with you to help find a resolution.

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [December 14, 2018, 6:05pm UTC](https://community.auth0.com/t/how-to-initialize-angularauth0provider-without-static-variables-with-angularjs-1-6-4/9263/3 "2018-12-14T18:05:11Z")

</div>


