Laravel5.6+ Passport Api Auth and web auth
I'm rather beginner in laravel, and I need some help.
Could somebody help me with a task?
I'm creating some web service, and the task is to connect front-end blade template with back-end via API requests.
I created API auth via Laravel passport, got token.
And the question is, how would be correctly get this auth token and use it in blade and in requests from blade to back-end?
i thought about cookies, or creating some middleware based on the cookies, - is it properly? perhaps there exist another right way to implement this?
Thanks!)
php laravel laravel-passport laravel-authorization
add a comment |
I'm rather beginner in laravel, and I need some help.
Could somebody help me with a task?
I'm creating some web service, and the task is to connect front-end blade template with back-end via API requests.
I created API auth via Laravel passport, got token.
And the question is, how would be correctly get this auth token and use it in blade and in requests from blade to back-end?
i thought about cookies, or creating some middleware based on the cookies, - is it properly? perhaps there exist another right way to implement this?
Thanks!)
php laravel laravel-passport laravel-authorization
add a comment |
I'm rather beginner in laravel, and I need some help.
Could somebody help me with a task?
I'm creating some web service, and the task is to connect front-end blade template with back-end via API requests.
I created API auth via Laravel passport, got token.
And the question is, how would be correctly get this auth token and use it in blade and in requests from blade to back-end?
i thought about cookies, or creating some middleware based on the cookies, - is it properly? perhaps there exist another right way to implement this?
Thanks!)
php laravel laravel-passport laravel-authorization
I'm rather beginner in laravel, and I need some help.
Could somebody help me with a task?
I'm creating some web service, and the task is to connect front-end blade template with back-end via API requests.
I created API auth via Laravel passport, got token.
And the question is, how would be correctly get this auth token and use it in blade and in requests from blade to back-end?
i thought about cookies, or creating some middleware based on the cookies, - is it properly? perhaps there exist another right way to implement this?
Thanks!)
php laravel laravel-passport laravel-authorization
php laravel laravel-passport laravel-authorization
edited Jan 2 at 10:09
PHP Hupp Technologies
1039
1039
asked Jan 2 at 7:58
Andry CorporateAndry Corporate
63
63
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It depends on what you are trying to do. Many people store the token in both cookie and browser localstorage. This has the benefit to access the token from both backend and frontend withouth any extra libraries. If you are building an SPA with SSR this maybe more difficult when it comes to refresh that token in a request which it happend during the ssr where you have no access to localstorage of the browser so it may be better to store it only on cookies. Personally i use both approaches depending on what i need to build.
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003009%2flaravel5-6-passport-api-auth-and-web-auth%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It depends on what you are trying to do. Many people store the token in both cookie and browser localstorage. This has the benefit to access the token from both backend and frontend withouth any extra libraries. If you are building an SPA with SSR this maybe more difficult when it comes to refresh that token in a request which it happend during the ssr where you have no access to localstorage of the browser so it may be better to store it only on cookies. Personally i use both approaches depending on what i need to build.
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
add a comment |
It depends on what you are trying to do. Many people store the token in both cookie and browser localstorage. This has the benefit to access the token from both backend and frontend withouth any extra libraries. If you are building an SPA with SSR this maybe more difficult when it comes to refresh that token in a request which it happend during the ssr where you have no access to localstorage of the browser so it may be better to store it only on cookies. Personally i use both approaches depending on what i need to build.
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
add a comment |
It depends on what you are trying to do. Many people store the token in both cookie and browser localstorage. This has the benefit to access the token from both backend and frontend withouth any extra libraries. If you are building an SPA with SSR this maybe more difficult when it comes to refresh that token in a request which it happend during the ssr where you have no access to localstorage of the browser so it may be better to store it only on cookies. Personally i use both approaches depending on what i need to build.
It depends on what you are trying to do. Many people store the token in both cookie and browser localstorage. This has the benefit to access the token from both backend and frontend withouth any extra libraries. If you are building an SPA with SSR this maybe more difficult when it comes to refresh that token in a request which it happend during the ssr where you have no access to localstorage of the browser so it may be better to store it only on cookies. Personally i use both approaches depending on what i need to build.
answered Jan 2 at 10:36
Vaggelis KspsVaggelis Ksps
19019
19019
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
add a comment |
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
Thanks, but what is the aim of storing the token in both cookie and browser localstorage ?
– Andry Corporate
Jan 8 at 9:47
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
As i already mentioned you can do it but you may have problem to refresh it if you are using ssr. Not saying that it is impossible but i can't find any reason of adding extra complexity to your code when you can do it similar. Maybe it is faster to get it from local storage than from cookie or the bundle is smaller without the need of a cookie-parser but in the end does it worth? Will this be the only cookie you will use so you don't want to add a cookie parser to client code?
– Vaggelis Ksps
Jan 8 at 13:05
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
it seems to me that it makes no difference to me to work with cookies or with local storage. im not going to use ssr yet
– Andry Corporate
Jan 9 at 9:02
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
Yeap i think this too.
– Vaggelis Ksps
Jan 9 at 9:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003009%2flaravel5-6-passport-api-auth-and-web-auth%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown