Regarding Custom URL & Auth Token

Hello,

I am trying to append token in my custom url In backend. But my Url append proper .It becomes 'http://localhost:4200/UrlDatasource'.


I have written CustomAdapter class as followed


export class CustomAdaptor extends ODataV4Adaptor {
constructor(private constantUrl: ConstantURL) {
super();
}
beforeSend(dm: DataManager, request: XMLHttpRequest) {
// this.token(dm, request);
const uuid = localStorage.getItem('uuid');
const token = localStorage.getItem('token');
request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
request.setRequestHeader('Authorization', `Bearer ${token}:${uuid}`);
// request.open("GET", this.constantUrl.ipUrl, true);
}
// async token(dm: DataManager, request: XMLHttpRequest) {
// const uuid = localStorage.getItem('uuid');
// // let token = await (await Auth.currentSession()).getAccessToken().getJwtToken();
// // localStorage.setItem
// const token = localStorage.getItem('token');
// dm.dataSource.headers = [{ 'Authorization': `Bearer ${token}:${uuid}` }]; // setting header \
// }
}

With the following method
private dataManager: DataManager = new DataManager({
url: this.constant.ipUrl + 'calendar/',
crudUrl: this.constant.ipUrl + 'calendar/',
adaptor: new CustomAdaptor(this.constant),
crossDomain: true
});

So could you please help me , how to append Custom URL with token

Thank you

1 Reply

HB Hareesh Balasubramanian Syncfusion Team June 23, 2021 12:40 PM UTC

Hi Milan, 

Greetings from Syncfusion Support..! 

We have prepared a sample based on your shared query “need to load the scheduler events using Custom Adaptor with Headers” using ODataV4 Adaptor, which can be viewed from the following link. 


class CustomAdaptor extends ODataV4Adaptor
  beforeSend(dm: DataManager, request: XMLHttpRequest) { 
    dm.dataSource.headers = [ 
      { Authorization: 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' } 
    ]; 
  } 
  . 
  . 

Note: In your shared snippets you have extends the ODataV4Adaptor but you have using Url and CrudUrl. ODataV4 adaptor does not need separate Url for CRUD actions. 

Kindly try the above sample and get back to us if you need any further assistance. 

Regards, 
Hareesh  


Loader.
Up arrow icon