Forum Stats

  • 3,733,828 Users
  • 2,246,828 Discussions
  • 7,856,887 Comments

Discussions

JWT Bearer token authentication in OJET

Zsolt Holman
Zsolt Holman Member Posts: 23 Red Ribbon
edited May 17 in Oracle JET

How to apply Bearer token authentication into the given model?

define(['ojs/ojcore', 

    'knockout', 

    'jquery', 

    'ojs/ojmodel',

...

],

 function(oj, ko, $, appUtils, signals) {  

  function TicketDeskViewModel() {

   var self = this;

   /* Variables */

   self.ticketListDataSource = ko.observable();

...

   /* List View Collection and Model */

   var ticketModelItem = oj.Model.extend({

    idAttribute: 'id'

   });

     

   var ticketListCollection = new oj.Collection(null, {

        url: "http://localhost:8080/tickets",

    model: ticketModelItem

   });

Best Answer

  • Zsolt Holman
    Zsolt Holman Member Posts: 23 Red Ribbon
    edited May 27 Accepted Answer

    It seems that the following approach works as expected:

    "you can add headers as one of the object input properties while calling the collection.fetch() method"


    self.model = oj.Model.extend({
            url: someURL,
            idAttribute: 'id'
    });
    var myModel = new self.model();
    var collection = oj.Collection.extend({
            url: someURL,
            model: myModel
    });
    self.myCollection = new collection();
    
    return new Promise(function (resolve, reject) {
        self.myCollection.fetch({
            headers: headers,
            success: function (collection, response, options) {
                resolve(response);
            }
        });
    };
    


Answers

Sign In or Register to comment.