forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support logto provider (lobehub#3630)
* ✨ support logto provider * 🎨 style: format code
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { OIDCConfig, OIDCUserConfig } from '@auth/core/providers'; | ||
|
||
import { authEnv } from '@/config/auth'; | ||
|
||
import { CommonProviderConfig } from './sso.config'; | ||
|
||
interface LogtoProfile extends Record<string, any> { | ||
email: string; | ||
id: string; | ||
name?: string; | ||
picture: string; | ||
sub: string; | ||
username: string; | ||
} | ||
|
||
function LobeLogtoProvider(config: OIDCUserConfig<LogtoProfile>): OIDCConfig<LogtoProfile> { | ||
return { | ||
...CommonProviderConfig, | ||
...config, | ||
id: 'logto', | ||
name: 'Logto', | ||
profile(profile) { | ||
// You can customize the user profile mapping here | ||
return { | ||
email: profile.email, | ||
id: profile.sub, | ||
image: profile.picture, | ||
name: profile.name ?? profile.username, | ||
providerAccountId: profile.sub, | ||
}; | ||
}, | ||
type: 'oidc', | ||
}; | ||
} | ||
|
||
const provider = { | ||
id: 'logto', | ||
provider: LobeLogtoProvider({ | ||
authorization: { | ||
params: { scope: 'openid offline_access profile email' }, | ||
}, | ||
// You can get the issuer value from the Logto Application Details page, | ||
// in the field "Issuer endpoint" | ||
clientId: authEnv.LOGTO_CLIENT_ID, | ||
clientSecret: authEnv.LOGTO_CLIENT_SECRET, | ||
issuer: authEnv.LOGTO_ISSUER, | ||
}), | ||
}; | ||
|
||
export default provider; |