Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
Raccoon 2021-06-12 18:54:01 +08:00
parent 6e8ff98039
commit cb1f263780
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
3 changed files with 7 additions and 6 deletions

View File

@ -9,7 +9,7 @@ import {URL} from "url";
const githubAuth = Router()
export = githubAuth
function githubUrl (path) {
function githubUrl(path) {
return config.github.enterpriseURL && new URL(path, config.github.enterpriseURL).toString()
}

View File

@ -1,7 +1,7 @@
import {InternalOAuthError, Strategy} from "passport-oauth2";
import config from "../../config";
export function parseProfile (data) {
export function parseProfile(data) {
const username = extractProfileAttribute(data, config.oauth2.userProfileUsernameAttr)
const displayName = extractProfileAttribute(data, config.oauth2.userProfileDisplayNameAttr)
const email = extractProfileAttribute(data, config.oauth2.userProfileEmailAttr)
@ -20,7 +20,7 @@ export function parseProfile (data) {
}
}
export function extractProfileAttribute (data, path) {
export function extractProfileAttribute(data, path) {
if (!data) return undefined
if (typeof path !== 'string') return undefined
// can handle stuff like `attrs[0].name`
@ -41,7 +41,8 @@ export function extractProfileAttribute (data, path) {
export class OAuth2CustomStrategy extends Strategy {
private _userProfileURL: any;
constructor (options, verify) {
constructor(options, verify) {
options.customHeaders = options.customHeaders || {}
super(options, verify)
this.name = 'oauth2'
@ -49,7 +50,7 @@ export class OAuth2CustomStrategy extends Strategy {
this._oauth2.useAuthorizationHeaderforGET(true)
}
userProfile (accessToken, done) {
userProfile(accessToken, done) {
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
if (err) {
return done(new InternalOAuthError('Failed to fetch user profile', err))

View File

@ -71,7 +71,7 @@ export class Revision extends Model<RevisionAttributes> implements RevisionAttri
length: number;
patch: string;
public readonly createdAt ?:number
public readonly createdAt ?: number
static initialize(sequelize: MySequelize): void {
Revision.init({