       })
       _h['X-Requested-With']='XMLHttpRequest'
 
-      bear = bearer.split('realm=')
-      bres = bear[1].split(",")
-      _uri = bres[0].replace(/^["]+|["]+$/g,"")
-      params = bres[1]
+      bear = bearer_to_parts(bearer)
 
-      $http.get(_uri,{headers:_h}).then(
+      $http.get(bear['url'],{headers:_h,params: bear['params']}).then(
         (response) ->
           deferred.resolve(response)
         (response) ->

    }


    create_token = (bearer) ->

      deferred = $q.defer()


    {
      create_token: create_token
      bearer_to_parts: bearer_to_parts
    }
])