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