-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from mirea-ninja/main
- Loading branch information
Showing
15 changed files
with
916 additions
and
90 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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,53 @@ | ||
import type { OAuthConfig, Provider } from 'next-auth/providers' | ||
import { nicknameValidation } from '@/lib/nickname-validation' | ||
import { Role } from '@prisma/client' | ||
|
||
interface UserInfo { | ||
username: string | ||
email: string | ||
name: string | ||
lastname: string | ||
middlename: string | ||
uid: string | ||
} | ||
|
||
type MireaProviderConfig = Required<Pick<OAuthConfig<any>, 'clientId' | 'clientSecret'>> | ||
|
||
export default function MireaProvider(options: MireaProviderConfig): Provider { | ||
return { | ||
id: 'mirea', | ||
name: 'RTU MIREA', | ||
type: 'oauth', | ||
version: '2.0', | ||
accessTokenUrl: 'https://login.mirea.ru/oauth2/v1/token/', | ||
requestTokenUrl: 'https://login.mirea.ru/oauth2/v1/token/', | ||
authorization: { | ||
url: 'https://login.mirea.ru/oauth2/v1/authorize/', | ||
params: { scope: 'basic' }, | ||
}, | ||
token: { | ||
url: 'https://login.mirea.ru/oauth2/v1/token/', | ||
}, | ||
userinfo: { | ||
url: 'https://login.mirea.ru/resources/v1/userinfo', | ||
}, | ||
checks: ['state'], | ||
async profile(profile: UserInfo) { | ||
const name = [profile.name, profile.lastname].join(' ') | ||
return { | ||
id: profile.uid, | ||
name, | ||
nickname: await nicknameValidation(name), | ||
email: profile.email, | ||
emailVerified: new Date(), | ||
userInfo: null, | ||
role: Role.USER, | ||
image: null, | ||
isBlocked: false, | ||
blockReason: null, | ||
} | ||
}, | ||
clientId: options.clientId, | ||
clientSecret: options.clientSecret, | ||
} | ||
} |
Oops, something went wrong.