What data can we get from socialite? - laravel

I'm using socialite laravel. What data can we get from socialite? Can we get location, phone, etc data from socialite?

according this docs, you can retrieve this user details :
// for All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

Related

Dynamic setApiCredentials for srmklive/paypal v3 in Laravel 8?

I'm trying to set up my PayPal config to switch between different seller accounts based on a table I have with client ID and client secret. The documentation says it's possible, but I can't find any example code to help me do it. Any ideas?
$provider = \Srmklive\PayPal\Facades\PayPal::setProvider();
$provider->setApiCredentials(config('paypal')); // Pull values from Config
$token = $provider->getAccessToken();
$provider->setAccessToken($token);

Issue in social login with google in vuejs (vueCLI)

I have used frontend in vuejs(vueCLI) and backend in laravel api. I have issue in social login with google in vuejs. I used vue-social-auth package. Here is this link (https://forum.vuejs.org/t/laravel-vue-social-auth-spa/54341). I have follow this link code. Login with Google Properly Work. But I can't get a response in User info like name, email or google_id.. please help
On your callback controller try to get user data using this code:
$platform='google';
$userData = Socialite::driver($platform)->user();
When You disable session You could use stateless method. The stateless
method may be used to disable session state verification. This is
useful when adding social authentication to an API:
$platform='google';
$userData = Socialite::driver($platform)->stateless()->user();

how to get the logged in user data in nuxtjs?

I'm using laravel backend and nuxtjs frontend, when I send a login request I get a response includes the logged in user informations with a token, the response looks like this:
{"message":"success","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiNzFkYjA1MWM2MTYxMmE4YzAyNWI2YjU3N2xMzJiNzJjMjI0MzRlY2IzNzYwNTg2N2NjOWQ5ZWEwY2MiMJM3uYEiZ8GSlPlQhIctVErO2KzwXOBxifWWoM7et_qT-mgvfsk3ljwiQF9iPQw-WeekBx8J8lcmxDLESa3tfE1Re1Xk2flkcBLmiI4JN2YHh08U1U","user":{"id":1,"role_id":4587,"firstname":"Hans","lastname":"newman","email":"newman#gmail.com","email_verified_at":null,"phone":"89498","skype":"gdgdfg","birthdate":"2021-05-02","address":"asdfaf","postalcode":14984,"city":"jisf","country":"isfisf","status":"mfof","created_at":"2021-06-16T09:33:08.000000Z","updated_at":"2021-06-16T09:39:41.000000Z","image":"1623835988-carlsen.png","description":"sfdgg","geo_lat":5.5,"geo_lng":8.1}}
after logging in I want to redirect the user to his profile page where he can see his data, how can I get the logged in user data from this response.
You can get the user details on the profile page using this.$auth.user which is provided by the nuxt auth module. This returns an array so you can access the actual details of the user using this.$auth.user[0] e.g this.$auth.user[0].email or this.$auth.user[0].firstname etc.
Also if you are using the nuxt module, you can access it using this.$store.state.auth.user.
Check out the nuxt auth module documentation for more info here
presuming the variable which you are saving response data in is response. you can access the user data via response.user. for accessing any data inside user you can access them further like response.user.id.
Beautified version of your response data for easier read:
{
"message":"success",
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiNzFkYjA1MWM2MTYxMmE4YzAyNWI2YjU3N2xMzJiNzJjMjI0MzRlY2IzNzYwNTg2N2NjOWQ5ZWEwY2MiMJM3uYEiZ8GSlPlQhIctVErO2KzwXOBxifWWoM7et_qT-mgvfsk3ljwiQF9iPQw-WeekBx8J8lcmxDLESa3tfE1Re1Xk2flkcBLmiI4JN2YHh08U1U",
"user":{
"id":1,
"role_id":4587,
"firstname":"Hans",
"lastname":"newman",
"email":"newman#gmail.com",
"email_verified_at":null,
"phone":"89498",
"skype":"gdgdfg",
"birthdate":"2021-05-02",
"address":"asdfaf",
"postalcode":14984,
"city":"jisf",
"country":"isfisf",
"status":"mfof",
"created_at":"2021-06-16T09:33:08.000000Z",
"updated_at":"2021-06-16T09:39:41.000000Z",
"image":"1623835988-carlsen.png",
"description":"sfdgg",
"geo_lat":5.5,
"geo_lng":8.1
}
}
if you're redirecting the user, you have to save the response in store so you can use it in another page. unless you are using Auth/Nuxt which saves the data in $auth.

Unable to get authenticated user using Laravel 5.8 and Auth0

I have a Laravel 5.8 API that I want to secure using Auth0. So far I've followed every step of this tutorial:
On the front side, Login/logout links are currently implemented in Blade, and this works fine, though the rendered content on the page is done using Vue Router, making AJAX requests to the API for the data.
The default User model in Laravel has been modified to store name, sub, and email per the tutorial, and this populates as well.
The API endpoint is secured using the jwt middleware created during the tutorial, and I can successfully submit a GET along with a hard-coded Bearer auth token in Postman and get a good response.
However, at some point I'd like to be able to pass an access token off to Vue so it can do its thing, but I'm unable to get the current authenticated user. After hitting Auth0, it redirects back to my callback route with auth gobbledlygook in the URL. The route in turn loads a controller method, and everything even looks good there:
// Get the user related to the profile
$auth0User = $this->userRepository->getUserByUserInfo($profile); // returns good user
if ($auth0User) {
// If we have a user, we are going to log them in, but if
// there is an onLogin defined we need to allow the Laravel developer
// to implement the user as they want an also let them store it.
if ($service->hasOnLogin()) { // returns false
$user = $service->callOnLogin($auth0User);
} else {
// If not, the user will be fine
$user = $auth0User;
}
\Auth::login($user, $service->rememberUser()); // "normal" Laravel login flow?
}
I'm not an expert on the framework, but the last line above seems to start the "normal" Laravel user login flow. Given that, shouldn't I see something other than null when I do auth()->user(), or even app('auth0')->getUser()?
Try using a simple tutorial if you're a beginner, I would recommend this
It uses a simple JWT package to create a jwt token which you can get when the user authenticates.
JWTAuth::attempt(['email'=>$email,'password'=>$password]);

Laravel get user info by Jwt token

I'm using laravel as my backend.
Once the user has logged into my app, all I have is just a token without any information regards the username or any other user details.
Once I retrive the JWT Token and store it in my frontend (angular2), how I can get the user details?
For the record, i'm using the following laravel library:
https://github.com/tymondesigns/jwt-auth
To get the user information
First get the token from JWTAuth like this:
$token = JWTAuth::getToken();
Then get the user from the token as follows:
$user = JWTAuth::toUser($token);
you can get user information like this way :
$user = JWTAuth::toUser(your_token_here);
I have tested just
$user = JWTAuth::toUser();
Without any parameter and it works as well
I am using Laravel 7.3 with tymon/jwt-auth 1.0
JWTAuth::parseToken()->authenticate();

Resources