本文整理汇总了TypeScript中oauth2orize.exchange类的典型用法代码示例。如果您正苦于以下问题:TypeScript exchange类的具体用法?TypeScript exchange怎么用?TypeScript exchange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了exchange类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findOne
}));
// Register Exchanges
function findOne(code: string, callback: (err: Error, code: {
clientId: string, userId: string, redirectURI: string, scope: string
}) => void): void {}
server.exchange(oauth2orize.exchange.code((client, code, redirectURI, done) => {
findOne(code, (err, code) => {
if (err) {
done(err);
} else if (client.id !== code.clientId) {
done(null, false);
} else if (redirectURI !== code.redirectURI) {
done(null, false);
}
// var token = utils.uid(256);
// var at = new AccessToken(token, code.userId, code.clientId, code.scope);
// at.save(function(err) {
// if (err) { return done(err); }
// return done(null, token);
// });
});
}));
// Implement Authorization Endpoint
class Clients {
static findOne(id: string, callback: (err: Error, client?: Clients) => void): void {
callback(new Error(), {} as Clients); // tslint:disable-line no-object-literal-type-assertion
}
redirectURI: string;
示例2: if
server.exchange(oauth2orize.exchange.password(
function(client: IClientDocument, username: string, password: string, scope: [string], done: Function): void {
checkScope(scope, function(err: any, scope: [string]): void {
if (err) {
done(err);
}
else {
const userModel: IUserDocumentModel = ModelManager.getUserModel();
userModel.findUserByEmail(username,
function(err: any, user: IUserDocument): void {
if (err) {
done(err);
}
else if (!user) {
done(undefined, false);
}
else {
user.verifyPassword(password,
function(err: any, match: boolean): void {
if (err) {
done(err);
}
else if (match === false) {
done(undefined, false);
}
else {
const accessTokenModel: IAccessTokenDocumentModel = ModelManager.getAccessTokenModel();
accessTokenModel.createToken("password", user._id, client._id, scope,
function(err: any, accessToken: IAccessTokenDocument): void {
if (err) {
done(err);
}
else if (accessToken === undefined) {
done(undefined, false);
}
else {
const refreshTokenModel: IRefreshTokenDocumentModel = ModelManager.getRefreshTokenModel();
refreshTokenModel.createToken("password", user._id, client._id, scope,
function(err: any, refreshToken: IRefreshTokenDocument): void {
if (err) {
done(err);
}
else if (refreshToken === undefined) {
done(undefined, false);
}
else {
done(undefined, accessToken.token, refreshToken.token, { expires_in: accessToken.expirationDate });
}
});
}
});
}
});
}
});
}
});
}));