本文整理汇总了TypeScript中oauth2orize.exchange.code方法的典型用法代码示例。如果您正苦于以下问题:TypeScript exchange.code方法的具体用法?TypeScript exchange.code怎么用?TypeScript exchange.code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2orize.exchange
的用法示例。
在下文中一共展示了exchange.code方法的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: function
server.exchange(oauth2orize.exchange.code(function(client: IClientDocument, code: string, redirectURI: string,
done: (err: any, token?: string | boolean, rToken?: string, option?: Object) => void): void {
const codeModel: IAuthCodeDocumentModel = ModelManager.getAuthCodeModel();
codeModel.getCode(code, client._id, function(err: any, authCode: IAuthCodeDocument): void {
if (err) {
done(err);
}
else if (authCode === undefined) {
done(undefined, false);
}
else {
authCode.useCode(function(err: any): void {
if (err) {
done(err);
}
else {
const accessTokenModel: IAccessTokenDocumentModel = ModelManager.getAccessTokenModel();
const refreshTokenModel: IRefreshTokenDocumentModel = ModelManager.getRefreshTokenModel();
accessTokenModel.disableOldToken(client._id, authCode.user, function(err: any): void {
if (err) {
done(err);
}
else {
refreshTokenModel.disableOldToken(client._id, authCode.user, function(err: any): void {
if (err) {
done(err);
}
else {
accessTokenModel.createToken("authorization_code", authCode.user, authCode.client, authCode.scope,
function(err: any, aToken: IAccessTokenDocument): void {
if (err) {
done(err);
}
else if (aToken === undefined) {
done(undefined, false);
}
else {
refreshTokenModel.createToken("authorization_code", authCode.user, authCode.client, authCode.scope,
function(err: any, rToken: IRefreshTokenDocument): void {
done(undefined, aToken.token, rToken.token, { expire_in: 3600 });
});
}
});
}
});
}
});
}
});
}
});
}));