-
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.
- Loading branch information
陈泉
committed
Nov 22, 2022
1 parent
61ffa36
commit c214996
Showing
12 changed files
with
220 additions
and
255 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
import { ApiCall } from "tsrpc"; | ||
import { ReqSocial, ResSocial } from "../../shared/protocols/auth/PtlSocial"; | ||
import { ApiCall, TsrpcError, TsrpcErrorType } from 'tsrpc' | ||
import { ReqSocial, ResSocial } from '../../shared/protocols/auth/PtlSocial' | ||
import authManager, { QQProvider } from '../../kernel/auth' | ||
import redis from '../../kernel/redis' | ||
|
||
export default async function (call: ApiCall<ReqSocial, ResSocial>) { | ||
// TODO | ||
call.error('API Not Implemented'); | ||
} | ||
const qqProvider = authManager.getInstance<QQProvider>('test-qq') | ||
if (!qqProvider) { | ||
return call.error( | ||
new TsrpcError({ | ||
message: 'No provider found', | ||
code: 'NO_PROVIDER', | ||
type: TsrpcErrorType.ApiError, | ||
}), | ||
) | ||
} | ||
|
||
let qqUrl = await redis.getCacheKey(`auth:${call.req.id}`) | ||
if (!qqUrl) { | ||
qqUrl = await qqProvider.getAuthorizationUrl({ | ||
srp: call.req.srp, | ||
erp: call.req.erp, | ||
}) | ||
await redis.setCacheKey(`auth:${call.req.id}`, qqUrl, 60) | ||
} | ||
|
||
return call.succ({ | ||
qq: qqUrl, | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import { authManager, QQProvider } from '../kernel/auth' | ||
|
||
export const testQQProvider = new QQProvider({ | ||
authManager.init<QQProvider>('qq', 'test-qq', { | ||
clientId: '102018312', | ||
clientSecret: 'AC1cz83mIbhZEfsr', | ||
canGetUnionId: true, | ||
name: 'test-qq', | ||
}) | ||
|
||
authManager.registerProvider(testQQProvider) |
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
Oops, something went wrong.