-
Notifications
You must be signed in to change notification settings - Fork 86
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
How can use Laravel passport #62
Labels
question
Further information is requested
Comments
adil-chbada
changed the title
How can use Laravel passport 😅
How can use Laravel passport
Feb 25, 2024
Hi, have same question |
same question |
import type { OAuthConfig, OAuthUserConfig } from '@auth/core/providers'
export interface PassportProfile {
id: number
name: string
email: string | null
created_at: string
updated_at: string
}
export default function Passport(
config: OAuthUserConfig<PassportProfile> & {
baseUrl: string
}
): OAuthConfig<PassportProfile> {
return {
id: "passport",
name: "Laravel Passport",
type: "oauth",
clientId: config.clientId,
clientSecret: config.clientSecret,
authorization: {
url: `${config.baseUrl}/oauth/authorize`,
params: {
scope: "",
},
},
token: {
url: `${config.baseUrl}/oauth/token`,
async request({ params, provider }) {
const res = await fetch(provider.token.url, {
method: "POST",
headers: {
"Cache-Control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
client_key: provider.clientId,
code: params.code,
grant_type: "authorization_code",
redirect_uri: provider.callbackUrl,
}),
}).then((res) => res.json());
return {
tokens: {
access_token: res.access_token,
expires_at: res.expires_in,
refresh_token: res.refresh_token,
token_type: res.token_type,
},
};
}
},
userinfo: {
url: `${config.baseUrl}/api/user`,
async request({ tokens, provider }) {
return await fetch(provider.userinfo?.url, {
headers: { Authorization: `Bearer ${tokens.access_token}` },
}).then(async (res) => await res.json());
},
},
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name,
email: profile.email,
}
},
checks: ["state"],
style: { bg: "#ff0000", text: "#fff", logo: "https://laravel.com/img/logomark.min.svg" },
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need a simple example on how to use Laravel Passport 🙏
The text was updated successfully, but these errors were encountered: