New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting JWT Refresh Token from login endpoints #398
Comments
I also waiting this features to be merged, for short term solution, I set the jwt token expire time to 8 hour |
Hi @rikoz, we are working on refresh support. Check this out #361 We haven't finished yet, but at the meantime you can use the new branch (feat/refresh). You can find the docs in the PR. |
Okay, I will check it out now. Let me know when it's updated into the main branch so i can update my node package. I will be waiting Can you give me a direct link to docs thanks I appreciate. |
Okay thanks, seen |
Any updates? |
Hi @danielmoeck, I'm sorry, I don't have any news about it. I had to stop working a few months ago due to personal problems. But yeah I agree, many people need this feature! Actually, I use this branch in my project in production! For me it works fine and stable. I guess is up to @pi0 to make the final reviews and merge it. |
@danielmoeck @mckraemer |
Thank you! I will try the branch you mentioned :) |
oh damn @JoaoPedroAS51 |
Hey @danielmoeck! Let's find out together! |
Yes that sounds great @JoaoPedroAS51 The errorcode is basically 401 Authorization: JWT undefined At the moment I'm using this version of the auth-module
|
Hi @danielmoeck, I guess the problem is in your config. We refactored the config in the feat/refresh branch. You can check the docs here #361 (comment) Try changing to this and tell me what happens: auth: {
localStorage: false,
strategies: {
local: {
_scheme: 'refresh',
token: {
property: 'access'
},
refreshToken: {
property: 'refresh_token' // change to your refresh token property
},
user: false,
endpoints: {
login: { url: '/api/v1/auth/jwt/create/', method: 'post' },
refresh: { url: '/api/v1/auth/jwt/refresh/', method: 'post' }, // change to your refresh token url
user: { url: '/api/v1/auth/users/me/', method: 'get' },
logout: false
},
tokenRequired: true,
tokenType: 'JWT'
}
}
} |
Wow thank you so much for your fast reply, thats really cool! I think everything works, I get my access and refresh token 👍 yeah! I'm just wondering why my auth/users/me call returns "Authentication credentials were not provided.". Do you know where I could've made a mistake? |
@danielmoeck I'm happy to know it worked! :) About "Authentication credentials were not provided", try to use |
@JoaoPedroAS51 I am very happy that you helped me! Awesome! 💯 Thank you so much! |
@danielmoeck Yay! And if you face any other problem, don't hesitate to contact me! I'll be happy to help! ;) |
Hi, Help Please!! How can i set the refresh token manually????? Just as I set the token with " |
Hi @Dav3rs! Just pass the refresh token as second parameter |
Thanks @JoaoPedroAS51 !!! Maybe that parameter could be updated in the docs in |
@Dav3rs Yes, you're right. I'll update it. |
@JoaoPedroAS51 I tried but checking cookie, refreshtoken is false.
EDIT: tried it with "@nuxtjs/auth-next" instead and it is working. "@nuxtjs/auth-next" and "@nuxtjs/auth" got me confused. Thank you :) |
Hi @stephenjason89! I'm happy to know it worked! :) You should make some refactors to ensure that your config works in auth: {
localStorage: false,
strategies: {
local: {
scheme: 'refresh', // `_scheme` is now `scheme`
token: {
property: 'access',
type: 'Bearer', // `tokenType` is now `token.type`
required: true // `tokenRequired` is now `token.required`
},
refreshToken: {
property: 'refresh_token' // change to your refresh token property
},
user: {
property: false, // `user` property is now `user.property`
autoFetch: true
},
endpoints: {
login: { url: '/api/v1/auth/jwt/create/', method: 'post' },
refresh: { url: '/api/v1/auth/jwt/refresh/', method: 'post' }, // change to your refresh token url
user: { url: '/api/v1/auth/users/me/', method: 'get' },
logout: false
}
}
}
} |
@JoaoPedroAS51 Thank you for replying to me.
But currently it is just passing refresh_token Currently my config is this
Thank you so much |
@stephenjason89 Laravel Passport it's pretty easy to configure. Just use |
@JoaoPedroAS51 How can i use the laravel/passport provider with a username and password? What I am trying to achieve is for users to be able to login using username and password which will be passed to my backend (passport) that will issue a token and a refresh token. Thank you |
@stephenjason89 It works with password grant, just need to set nuxt.config auth: {
laravelPassport: {
name: 'laravelPassportPassword',
provider: 'laravel/passport',
endpoints: {
user: {
url: '/api/auth/user'
}
},
token: {
maxAge: 1800
},
refreshToken: {
maxAge: 60 * 60 * 24 * 30
},
clientId: 'client-id',
clientSecret: 'client-secret',
grantType: 'password'
}
} Then to login: this.$auth.loginWith('laravelPassport', {
data: {
username: 'test@test.com',
password: '12345678'
}
}) You can check the demo from the repo: https://github.com/nuxt-community/auth-module/tree/dev/demo Laravel Passport documentation for Password Grant flow: https://laravel.com/docs/8.x/passport#password-grant-tokens |
@JoaoPedroAS51 You are awesome. I am trying it now. Sorry I was editing my previous question when you replied. The same challenge is what i am facing with social login.
This works only half way. I will have a token from facebook but I won't be able to verify on my server if this is already registered and if it is, issue a token from passport. Thank you :) |
I might be missing something, i copied the config on the repo you linked me. here's my nuxt
Then i called it like this
Everytime i try to login, the only thing i see in my network tab is index.js EDIT: i actually went ahead and copied the whole Auth block and used
But there were no errors nor were there network traffic to my laravel endpoint. I only see index.js and my default error handler. |
@stephenjason89 I think your laravel target should be Sorry for the delay. I'm not used to laravel socialite. I'm doing some research. |
@JoaoPedroAS51 I changed mine to port 80 |
ok |
Thank you for helping me, I will try to do something about the laravel socialite and will report back once i figure it out. |
@stephenjason89 About the facebook I think you should set the public function user ()
{
$user = Socialite::driver('facebook')->userFromToken(request()->bearerToken());
return response()->json($user)
} |
@JoaoPedroAS51 I will try that now. |
For facebook: auth: {
strategies: {
facebook: {
endpoints: {
userInfo: 'http://localhost/api/auth/facebook/user'
},
clientId: '...'
},
}
}
Ok, I'll see if I find where is the error. |
@JoaoPedroAS51 Thank you so much. You reply so fast. I'm so grateful for your help. |
I'm happy to help! :) |
@stephenjason89 Can you add me on discord? Joao Pedro AS51#1284 |
I will add you now :) |
Thank you so much for helping me @JoaoPedroAS51 I really appreciate it. |
Good day @JoaoPedroAS51 `auth: {
},` I get the error message XHRGEThttp://127.0.0.1:8000/account/current-user/ detail "Given token not valid for any token type" I would be grateful for your assistance. Thank you |
Hi @osahene! Let's see if we can make this work! :) |
Hi @JoaoPedroAS51,
}, When I console log the response I get The loggedInUser, isAuthenticated as well as the auth. user returns false. thank you |
I had a solution to the issue through Dev Internals https://www.youtube.com/watch?v=Tqm9hVCSQDI&list=PL0xSLrZOcI4sbSEO9c5NnlPYWAvJzl05I&index=11 |
hi, @JoaoPedroAS51, i have issue with refresh token endpoint, can you help me please?
|
@iamr0man I have the same issue. How did you solve your problem? |
What problem does this feature solve?
Hello, I have a feature request and i need help from anyone who can help
What I have::
please i'm making use of JWT setting the access token in the property name... the problem is access token expires after some minutes and becomes invalid throwing a 401 (Unauthorized) error and this will make the application to logout.
What I want to acheive::
A way to set the refresh token so when access token expires and throws such error, I should intercept to use refresh token to fetch a new access token and then repeat request.
I'm using DRF for backend.
I really need your help as this app deploys in few days and i need to fix it up
Thanks
What does the proposed changes look like?
Please add another optional field to login endpoint that sets refresh token.... I already see the auth module has the function to set it. An axios interceptor will take care of the rest feature of having to fetch a new access token once expired using the refresh token in payload.
Also a new endpoint to specify what url is called using this refresh token to fetch access
To look something like this
and then a $auth.tokenRefresh function.
Thanks
The text was updated successfully, but these errors were encountered: