question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to consume REST service with Basic Authentication

See original GitHub issue

Hi All,

I have java REST services and consumer in Angularjs 1.3. Services are JSON based and expect BASIC authentication (username-password). In AgJs 1.3, I used Base64 factory code (found on google) for creating basic authentication token from username and password and able to consume services SUCCESSFULLY.

I read HTTP class in AgJs 2.0 documentation but I didn’t find any information about basic authentication.

Could anybody please provide sample code to consume REST services in Angularjs 2.0 using BASIC authentication?

Thanks in advance! Best Regards!

My AgJs 1.3 code:

var url = “http://x.x.x.x:xxxx/data/” + number;

    $http.defaults.headers.common['Authorization'] = 'Basic ' + Base64.encode('username' + ':' + 'password');
    $http.defaults.headers.common['Content-Type'] = 'application/json';

    $http({ method: 'GET', url: url }).
            success(function (data, status, headers, config) {
               alert(data);
            }).
            error(function (data, status, headers, config) {
                alert("error: " + data);
            });

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PTAB-TEchcommented, Aug 16, 2018

Hi, i am calling switch API’s for that i need to login to it first from postman i am using Authorization type basic and setting username ans password , i want to implement this in code i am using Angular 6.

please help me to get solution

Thanks in advance Tanaji

0reactions
angular-automatic-lock-bot[bot]commented, Sep 14, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java restful webservices with HTTP basic authentication.
1) Username and password are combined into a string "username:password" · 2) The resulting string is then encoded using Base64 encoding · 3)...
Read more >
How do we consume rest api with Http basic authentication in ...
1 Answer 1 ; = new HttpGet ; // Combine the user and password pair into the right format String auth ; =...
Read more >
Basic Authentication with the RestTemplate - Baeldung
In this tutorial, we'll learn how to use Spring's RestTemplate to consume a RESTful Service secured with Basic Authentication.
Read more >
Add Basic Authentication to an Exposed REST API
In the Logic tab, open the Integrations folder. Select the exposed REST API you want to change and set its "Authentication" property to...
Read more >
How to use Basic Authentication with Rest Template in Spring ...
Basic authentication provides one of the ways to secure REST API. It's not the most secure way compared to OAuth or JWT based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found