This larabit covers connecting socialite to github https://laracasts.com/series/jeffreys-larabits/episodes/39
Laravel Socialite Github Oauth Authentication
I"m trying to host my nuxt application with a laravel api where i"m using laravel socialite to authenticate into github, but everytime after accepting the application, being redirect to the callback url and sent the code to the backend i"m getting 401 bad credentials in the backend. The problem is that this only happens in production under the frontend domain: desafio-reportei.ejsocial.com and the backend domain: backend.ejsocial.com, when i try the same code in my local environment under localhost it works fine.
Thats my backend controller: public function redirect() { return Socialite::driver("github")->stateless()->redirect(); }
public function callback()
{
$oAuthUser = Socialite::driver("github")->stateless()->user();
$user = User::updateOrCreate(
['email' => $oAuthUser["name"]],
['name' => $oAuthUser["email"]],
["user_id" => $oAuthUser["id"]],
["avatar_url" => $oAuthUser["avatar_url"]],
["html_url" => $oAuthUser["html_url"]]
);
$token = $user->createToken(env('SECRET'))->plainTextToken;
return response()->json([
'user' => $user,
'token' => $token
]);
}
my nuxt callback url:
import axios from "axios"; import { useRoute, useRouter } from "vue-router";
const isLoading = ref(true); const route = useRoute(); const router = useRouter(); const code = route.query.code;
const handleGithubCallback = async () => {
const response = await axios.get(http://backend.ejsocial.com/api/auth/github/callback?code=${code});
const token = useCookie("token");
token.value = response.data.token;
isLoading.value = false;
router.push("/");
};
and my github oauth app: Homepage URL: http://desafio-reportei.ejsocial.com Authorization callback URL: http://desafio-reportei.ejsocial.com/auth/github/callback
Please or to participate in this conversation.