本文整理匯總了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 });
}
});
}
});
}
});
}
});
}
});
}));