Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
Cómo extraer el token auth0 de la URL en ui.router

Tengo una aplicación angular1 que usa auth0.js para autenticarse. Quiero almacenar el token en mi tokenService cuando mi aplicación recibe la devolución de llamada de auth0.

https://localhost:44316/Run#access_token=ufgdfgfdNCRfYBP&expires_in=86400&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2Ryb2JsZXIuZXUuYXV0gDfgAuY29tLyIsInN1fgf6Imdvb2dsZS1vYXV0aDJ8MTAzOTAwNjAwNjI0MTg2MTIyMDAwIiwiYXVkIjoieU1XYUt3VmF1ckhsaU5hemZVM3c0QUtzV2hXVEFJSHIiLCJleHAiOjE0OTM0ODk0MDgsImlhdCI6MTQ5MzQ1MzQwOH0.NuRxvsOIoB5_zZLl5aZd7zYgAhXxpvEhXXDJ1dkurRo&token_type=Bearer

¿Cómo puedo crear un estado ui.router que coincida con la URL para que mi resolución pueda procesar la solicitud y obtener datos adicionales?

 $stateProvider .state('RecieveAuth', { url: "", resolve: tokenresolve, controller: function($tate){ $state.go("MainSite"); }, data: { requirelanguage: true, requireLogin: true }, })

no funciona, y si uso "/" como URL, no coincide con "#accesstoken="

Ya intenté hacer el procesamiento en ejecución, pero en esta versión no sé cómo hacer que los controladores esperen hasta que se complete mi llamada http.

Cualquier ayuda es muy apreciada.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Encontré una solución usando un inyector:

 $urlRouterProvider.otherwise(function ($injector, $location) { var state = $injector.get('$state'); var $rootScope = $injector.get("$rootScope"); var accountSvc = $injector.get("accountSvc"); var tokenService = $injector.get("tokenService"); console.log('location', $location, 'location.search()', $location.search()); if ($location.$$url.indexOf('/access_token=') >= 0) { accountSvc.authenticateAndGetProfile(function () { tokenService.Reload(); $rootScope.Authenticate(); state.go('Folders'); }, function () { state.go('Folders'); }); } return $location.path(); });
over 4 years ago · Santiago Trujillo Denunciar

0

En su función de resolución, llame a un servicio desde cualquier fábrica, por ejemplo (donde Data es una fábrica):

 $stateProvider .state('RecieveAuth', { url: "", resolve: { content: function(Data) { return Data.isAuth() } }, controller: function($tate){ $state.go("MainSite"); }, data: { requirelanguage: true, requireLogin: true }, })

Y en su Factoría de datos, la función isAuth() puede verse así:

 let isAuth = function() { // Get Token from URL or local storage let urlParameters = $location.search(); let token = ''; if ( urlParameters.hasOwnProperty('accesstoken') ) { tokenSurvey = urlParameters['accesstoken']; } let deferred = $q.defer(); $resource('Call your server with the token retrieved above').query().$promise.then( (data) => { //User successfully, auth, rreturn resolve promise deferred.resolve(data); }, (error) => { // Eror during Auth, reject promise, state will not be loaded (you have to handle errors in this case) deferred.reject(error); }); return deferred.promise; };
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda