2017-05-22 20:58:25 +02:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-07-05 13:26:25 +02:00
|
|
|
import * as Promise from 'bluebird'
|
2017-05-22 20:58:25 +02:00
|
|
|
|
2017-06-16 09:45:46 +02:00
|
|
|
import { UserModel } from '../user'
|
2017-05-22 20:58:25 +02:00
|
|
|
|
2017-06-10 22:15:25 +02:00
|
|
|
export type OAuthTokenInfo = {
|
|
|
|
refreshToken: string
|
|
|
|
refreshTokenExpiresAt: Date,
|
|
|
|
client: {
|
|
|
|
id: number
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
id: number
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 20:58:25 +02:00
|
|
|
export namespace OAuthTokenMethods {
|
2017-07-05 13:26:25 +02:00
|
|
|
export type GetByRefreshTokenAndPopulateClient = (refreshToken: string) => Promise<OAuthTokenInfo>
|
|
|
|
export type GetByTokenAndPopulateUser = (bearerToken: string) => Promise<OAuthTokenInstance>
|
|
|
|
export type GetByRefreshTokenAndPopulateUser = (refreshToken: string) => Promise<OAuthTokenInstance>
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type RemoveByUserId = (userId) => Promise<number>
|
2017-05-22 20:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface OAuthTokenClass {
|
|
|
|
getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClient
|
|
|
|
getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser
|
|
|
|
getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser
|
|
|
|
removeByUserId: OAuthTokenMethods.RemoveByUserId
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface OAuthTokenAttributes {
|
|
|
|
accessToken: string
|
|
|
|
accessTokenExpiresAt: Date
|
|
|
|
refreshToken: string
|
|
|
|
refreshTokenExpiresAt: Date
|
|
|
|
|
|
|
|
User?: UserModel
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface OAuthTokenInstance extends OAuthTokenClass, OAuthTokenAttributes, Sequelize.Instance<OAuthTokenAttributes> {
|
|
|
|
id: number
|
|
|
|
createdAt: Date
|
|
|
|
updatedAt: Date
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface OAuthTokenModel extends OAuthTokenClass, Sequelize.Model<OAuthTokenInstance, OAuthTokenAttributes> {}
|