These are chat archives for canjs/canjs

11th
Jul 2017
Frank Lemanschik
@frank-dspeed
Jul 11 2017 00:00
the PR: donejs/donejs#991 not perfect needs extra work but its there a lot of stuff todo :)
Kevin Phillips
@phillipskevin
Jul 11 2017 00:42
@runn-vermel, everything using can-observation/reader/reader should be using can-stache-key now
since this is just changing the file structure, it isn't a breaking change
oh, I see your issue now
we can just continue the discussion there since Justin responded there already
Frank Lemanschik
@frank-dspeed
Jul 11 2017 00:44
ok i am still working on it to make it complet
ah you meand the other lol
Kevin Phillips
@phillipskevin
Jul 11 2017 00:45
yeah, sorry
I haven't looked at your issue yet @frank-dspeed
Frank Lemanschik
@frank-dspeed
Jul 11 2017 00:45
its ok :)
it got bigger then expected hihi
Viktor Busko
@Lighttree
Jul 11 2017 09:37
Guys, if I need to get authentication token before each call to API. It is very short-living token, so it is a must to get it before each call :(. What the best way to do this ? Is there something that I can do from canjs side ?
like I have my canjs models can-connect etc. But in order to work with this I have to get the token and set header.
Eben
@eben-roux
Jul 11 2017 09:39
where do you get the token from and how? e.g. if you need to make a call to an Authentication endpoint of sorts what data do you pass?
for my own implementations I typically have a session token (GUID) that I keep locally and add as a header but since your token seems to expire pretty quickly your design will differ
Viktor Busko
@Lighttree
Jul 11 2017 09:47
Currently its like:
getToken: function () {
     return $.ajax({
          url: `/login/userToken`
     })
}
Model().getToken().done(function (res) {
       Model().doWhatINeed();
})
But this seems not very nice
Eben
@eben-roux
Jul 11 2017 09:49
ok, so how would that /login/userToken authenticate the user?
the reason I ask is that you are going to have different options depending on how your system works. You could continue to ask for the token before each request using , say, a prefilter (this is mine):
$.ajaxPrefilter(function(options, originalOptions) {
    options.beforeSend = function(xhr) {
        if (security.token) {
            xhr.setRequestHeader('sentinel-sessiontoken', security.token);
        }

        if (originalOptions.beforeSend) {
            originalOptions.beforeSend(xhr);
        }
    };
});
Eben
@eben-roux
Jul 11 2017 09:54
of course you'd want to exclude your token request to prevent an infinite loop...
Viktor Busko
@Lighttree
Jul 11 2017 09:54
its a bit blackbox for me, but I think what is happening... there is cookie based session, and during this session you can call this endpoint and it returns token for token based authentication. So the idea is that you can get tokens only when your original session alive :D
Eben
@eben-roux
Jul 11 2017 09:54
ah
that is quite limiting then :)
if you had some server-side api you could've sent the actual identifier and have the server check the authentication
Viktor Busko
@Lighttree
Jul 11 2017 09:55
actually this ajax prefilter approach someting that I was thinking about.
Eben
@eben-roux
Jul 11 2017 09:56
perhaps in your "beforeSend" you could fetch the token... but do ignore your token fetch in the prefilter
Viktor Busko
@Lighttree
Jul 11 2017 09:56
not sure will it work with all canjs things
Frank Lemanschik
@frank-dspeed
Jul 11 2017 09:56
you could make a behavier for that
i think thats the normal way
Eben
@eben-roux
Jul 11 2017 09:57
canjs is built over these... if you are using jquery directly it shouldn't affect canjs...
Frank Lemanschik
@frank-dspeed
Jul 11 2017 09:57
example is the feathers authentication behavier
Eben
@eben-roux
Jul 11 2017 09:57
mmm... that actually makes sense
Viktor Busko
@Lighttree
Jul 11 2017 09:57
not sure that I understand correctly
Eben
@eben-roux
Jul 11 2017 09:57
having my own jquery/can-connect joy at the moment
behaviours are a can-connect thing
Frank Lemanschik
@frank-dspeed
Jul 11 2017 09:58
to be more exact it is what can-connect should do
Eben
@eben-roux
Jul 11 2017 09:58
basically a pipeline (a la pipes and filters)
Frank Lemanschik
@frank-dspeed
Jul 11 2017 09:58
not only that also the data request it self
like the url behavier
Eben
@eben-roux
Jul 11 2017 09:59
in your case you'd add a new behaviour up-front to fetch the token... never built my own behaviour before but shouldn't be too difficult... I hope...
Viktor Busko
@Lighttree
Jul 11 2017 09:59
aaaah this is exactly what I need thank you @frank-dspeed
will try to use it :)
Eben
@eben-roux
Jul 11 2017 10:03
do you need to add a header to your call?
Viktor Busko
@Lighttree
Jul 11 2017 10:03
yep
Eben
@eben-roux
Jul 11 2017 10:03
@frank-dspeed : would that be possible using a behaviour then?
if you consider my example above... would that fit into the behaviour paradigm?
this is the feathersjs session behavier
its what allows to create destroy auth a session
you can adjust that as feathers simply usses jwt it self
from passport wich is wide used
@Lighttree all fits into a behavier
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:10
a behavier is only a object with some defined stuff like create get destroy
so you need to supply a method for getting your tooken
Viktor Busko
@Lighttree
Jul 11 2017 10:12
Thanks for the explanation
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:12
oh no need to thank me for that
i am happy that i understood that my self 4 month befor
:D
took me only 9 month to understand that this is what does the requests and such stuff
found that out really late
Eben
@eben-roux
Jul 11 2017 10:18
ok, but how does the behaviour relate to setting a token though?
is there some relationship between an ajax request and a behaviour that I am missing?
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:18
it sets the token where ever it likes
example in this session behavier it does that in a session store
that gets also synced with localstorage
Eben
@eben-roux
Jul 11 2017 10:18
not token... the header that goes across the wire
the one I set in my prefilter for instance
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:19
feathersClient
its in the feathers client
you need to add that logic directly to your behavier
the feathersclient does in this example the request with the header
so in your case the jquery ajax request
Eben
@eben-roux
Jul 11 2017 10:20
I'm afraid I have never used feathers... can you perhaps link to the code that sets the header?
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:21
why should i ? if your not using it
?
you want to know how to set headers on jquery xhr right?
Eben
@eben-roux
Jul 11 2017 10:21
ah, so still ajax and still outside the behaviur
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:21
you can do ajax inside the behavier
Eben
@eben-roux
Jul 11 2017 10:21
I'd like to see the sample code... but don't fret... I can go hunting for it myself :)
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:21
you do it all in behavier
hmmmm hmmm i have a idea
bitballs should have a example
that is near to that
but not using headers
i think its easy to add headers
Eben
@eben-roux
Jul 11 2017 10:22
now that's the disconnect I'm experiencing... adding a header in a perfilter vs in a behaviour
adding headers is a breeze in ajax
no problem there
trying to tie it back to behaviours
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:23
ya you could also release and share your result
i think it exist nothing like that already
a ajax jwt auth
Frank Lemanschik
@frank-dspeed
Jul 11 2017 10:34
@eben-roux the alternativ to this is coding a own little client and implament it like the google client in this example
Gregg Roemhildt
@roemhildtg
Jul 11 2017 17:12
Just noticed the new can-slot and can-template Great stuff!
Matthew Phillips
@matthewp
Jul 11 2017 17:34
Thanks! :)
Chasen Le Hara
@chasenlehara
Jul 11 2017 17:36
@roemhildtg Yay, let us know how you use it!
I tried to come up with a not-too-contrived example for the release notes: https://github.com/canjs/canjs/releases/tag/v3.9.0
Gregg Roemhildt
@roemhildtg
Jul 11 2017 17:47
@chasenlehara will do! The modal example is very helpful for seeing the possibilities
Chasen Le Hara
@chasenlehara
Jul 11 2017 17:48
Ok cool, glad to hear it was a helpful example :)
Gregg Roemhildt
@roemhildtg
Jul 11 2017 17:51
To me, it seems sort of like jynja blocks
override able sections of a template
Frank Lemanschik
@frank-dspeed
Jul 11 2017 17:54
lol
i don't understand can slot
for me it looks like can component in can component
Gregg Roemhildt
@roemhildtg
Jul 11 2017 17:54
One thing that would be useful is to have a {{super}} tag, like in jynja. Where if I override a slot with a template, I can still render the default.
Frank Lemanschik
@frank-dspeed
Jul 11 2017 17:54
wich worked befor
:D
Gregg Roemhildt
@roemhildtg
Jul 11 2017 17:55
can slot solves the issue where I want to have different override able parts to my component's template
Kevin Phillips
@phillipskevin
Jul 11 2017 17:55
it gives the ability to have multiple <content> sections
that are named and put in specific places
Gregg Roemhildt
@roemhildtg
Jul 11 2017 17:56
:+1: @phillipskevin
Eben
@eben-roux
Jul 11 2017 17:56
can-slot appears to be what Ember calls an outlet
Frank Lemanschik
@frank-dspeed
Jul 11 2017 17:56
i think it is usefull even if i don't understand it at present :)
the idea anyway
not the implementation
Frank Lemanschik
@frank-dspeed
Jul 11 2017 21:04
got the idea and it is cool if i later understand how to use it :)
Viktor Busko
@Lighttree
Jul 11 2017 22:06
@matthewp , just letting you know that this is fixed: webpack/webpack#5198
Just checked with "webpack": "^3.2.0" can-fixture seems fine.