fix(auth): correctly checks whether authN strategies are enabled before loading them

+ cleans up gql api on apps
This commit is contained in:
Dimitrie Stefanescu
2020-07-15 10:52:07 +01:00
parent f9eea0eac2
commit 436bdf8df4
3 changed files with 9 additions and 49 deletions
-21
View File
@@ -19,26 +19,5 @@ module.exports = {
}
},
Mutation: {
async appAuthorize( parent, args, context, info ) {
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'apps:authorize' ) // TODO
// Implicit grant flow: returns the token directly
// let token = await createAppToken( { userId: context.userId, appId: args.appId } )
// return token
// TODO: Implement authorization code grant
let accessCode = await createAuthorizationCode( { userId: contex.userId, appId: args.appId, challenge: args.challenge } )
return accessCode
},
async appGetToken( parent, args, context, info ) {
let result = await exchangeAuthorizationCodeForToken( { appId: args.appId, appSecret: args.appSecret, accessCode: args.accessCode, challenge: args.challenge } )
// args.appId, args.appSecret, args.accessCode
},
async appRefreshToken( parent, args, context, info ) {
// TODO
}
}
}
-23
View File
@@ -31,26 +31,3 @@ type AuthStrategy {
url: String!,
color: String
}
extend type Mutation {
"""
Authorizes an app on behalf of a user. Returns an access code that can be exchanged
by the application for an api token.
"""
appAuthorize( appId: String!, challenge: String! ): String!
"""
Exchanges an access code for an api token.
"""
appGetToken( appId: String!, appSecret: String!, accesCode: String!, challenge: String! ): AppTokenResponse!
"""
Refreshes an expired token.
"""
appRefreshToken( appId: String, appSecret:String!, refreshToken: String! ): AppTokenResponse!
}
type AppTokenResponse {
"""
The actual bearer token.
"""
token: String!
refreshToken: String!
}
+9 -5
View File
@@ -74,13 +74,17 @@ exports.init = ( app, options ) => {
// Strategies initialisation & listing
let githubStrategy = require( './strategies/github' )( app, session, sessionAppId, finalizeAuth )
authStrategies.push( githubStrategy )
if ( process.env.STRATEGY_GITHUB === 'true' ) {
let githubStrategy = require( './strategies/github' )( app, session, sessionAppId, finalizeAuth )
authStrategies.push( githubStrategy )
}
let googStrategy = require( './strategies/google' )( app, session, sessionAppId, finalizeAuth )
authStrategies.push( googStrategy )
if ( process.env.STRATEGY_GOOGLE === 'true' ) {
let googStrategy = require( './strategies/google' )( app, session, sessionAppId, finalizeAuth )
authStrategies.push( googStrategy )
}
if ( process.env.STRATEGY_LOCAL ) {
if ( process.env.STRATEGY_LOCAL === 'true' ) {
let localStrategy = require( './strategies/local' )( app, session, sessionAppId, finalizeAuth )
authStrategies.push( localStrategy )
}