Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:20:52+00:00 2026-06-13T06:20:52+00:00

I am trying to implement a custom API authentication method as suggested below. Password

  • 0

I am trying to implement a custom API authentication method as suggested below.

Password protecting a REST service?

However, I am having some trouble with the authkey. I would like to save my authkey received as a global variable but I can’t seem to change it, it always become the same value as what it is defined to be at the start.

I am implement global variable using angular (v0.9) service.

snippet of my code

angular.service('Authkey', function(){
  return {
"authkey": "0000"
 };
});

controller

function LoginCtrl(Login_, Authkey_){
this.login = function(){
Login_.query({"Username": this.email,"Password": this.password}, function(response){
        if (response.success === "true") {
            Authkey_.authkey = response.AuthKey;
            console.log(Authkey_.authkey);
            window.location="/main.html";

        } 
    }); 
}
}

Yup. It always become 0000 after the page is changed.

Appreciate all help I can get. Thank you..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:20:54+00:00Added an answer on June 13, 2026 at 6:20 am

    try this:

    angular.service('Authkey', function(){
      var authkey = "000";
      return {
         getAuthKey: function(){
            return authkey;
         }, 
         setAuthKey: function(key){
            authkey = key;
         }
     };
    });
    
    //in controller:
    
    Authkey_.setAuthKey(response.AuthKey);
    consol.log(Authkey_.getAuthKey());
    

    the difference here is that the AuthKey service has a closure on the key and you get/set that value.

    in your code you always return the same thing. your setting of the key in the service has no effect on your return value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement some custom model metadata in ASP.NET MVC 3. I can't
I am trying to implement a custom endpoint/operation extension in my WCF service. I
I am trying to implement a custom authorization attribute on my Web API controllers,
I am trying to implement a custom slider as shown in figure below. what
I'm trying to implement a REST API to my website. My problem is that
I'm new to ASP.NET, and I'm trying to implement a custom ObjectDataSource Insert method.
Trying to implement Piwik using REST API over http but need a little help.
I am trying to implement some custom security code into SSRS 2008 (not R2)
I was trying to implement custom validation attribute by inheriting from ValidationAttribute and found
im trying to implement a custom error page, what i want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.