I have a rest call which works fine when i log in to the parent site ( the site which provides the rest call) from another browser tab. But when i use the call directly, (without logging in to the site from another tab) i'm getting error 401 Unauthorised. This is expected, but how do i authenticate my rest call?

On searching the internet, i've seen a bunch of codes using this:
proxy:{
type: 'rest',
url: 'somesite.com/restservice1',
method: 'GET',
username: 'user1',
password: 'pass'
}

and also this:
proxy:{
type: 'rest',
url: 'somesite.com/restservice1',
method: 'GET',
extraParams:{
username: 'user1',
password: 'pass'

}
}

None of them work. How do i get it working? As many sites (almost all of them) use authentication with their rest services, there's got to be a way.