feat(authentication): add credentials processing

This commit is contained in:
Wroud
2020-05-12 17:44:24 +03:00
parent f1439c9eca
commit 70bdf2e440
4 changed files with 31 additions and 10 deletions
@@ -12,6 +12,8 @@ import { injectable } from '@dbeaver/core/di';
import { NotificationService } from '@dbeaver/core/eventsLog';
import { GraphQLService, UserAuthInfo } from '@dbeaver/core/sdk';
import { AuthProviderService } from './AuthProviderService';
@injectable()
export class AuthInfoService {
@observable private user: UserAuthInfo | null = null;
@@ -19,6 +21,7 @@ export class AuthInfoService {
constructor(
private graphQLService: GraphQLService,
private notificationService: NotificationService,
private authProviderService: AuthProviderService,
) { }
get userInfo() {
@@ -29,8 +32,12 @@ export class AuthInfoService {
if (this.user) {
throw new Error('User already logged in');
}
const processedCredentials = this.authProviderService.processCredentials(provider, credentials);
const { user } = await this.graphQLService.gql.authLogin({ provider, credentials });
const { user } = await this.graphQLService.gql.authLogin({
provider,
credentials: processedCredentials,
});
this.user = user;
return this.user;
@@ -6,6 +6,8 @@
* you may not use this file except in compliance with the License.
*/
import { createHash } from 'crypto';
import { injectable } from '@dbeaver/core/di';
import {
GraphQLService, CachedResource, AuthProviderInfo
@@ -21,6 +23,27 @@ export class AuthProviderService {
private graphQLService: GraphQLService,
) { }
processCredentials(providerId: string, credentials: any) {
const provider = this.providers.data.find(provider => provider.id === providerId);
if (!provider) {
return credentials;
}
const credentialsProcessed = { ...credentials };
for (const parameter of provider.credentialParameters) {
if (parameter.encryption === 'hash' && parameter.id in credentialsProcessed) {
const md5Hash = createHash('md5')
.update(credentialsProcessed[parameter.id])
.digest('hex')
.toUpperCase();
credentialsProcessed[parameter.id] = md5Hash;
}
}
return credentialsProcessed;
}
private async refreshAsync(data: AuthProvider[]): Promise<AuthProvider[]> {
const { providers } = await this.graphQLService.gql.getAuthProviders();
@@ -22,8 +22,6 @@ query getAuthProviders {
id
displayName
description
editable
identifying
admin
user
possibleValues
-7
View File
@@ -41,8 +41,6 @@ export type AuthCredentialInfo = {
id: Scalars["ID"];
displayName: Scalars["String"];
description?: Maybe<Scalars["String"]>;
editable?: Maybe<Scalars["Boolean"]>;
identifying?: Maybe<Scalars["Boolean"]>;
/** This field must be shown in admin panel */
admin?: Maybe<Scalars["Boolean"]>;
/** This field must be shown in login form */
@@ -57,7 +55,6 @@ export type AuthProviderInfo = {
icon?: Maybe<Scalars["ID"]>;
description?: Maybe<Scalars["String"]>;
isDefault?: Maybe<Scalars["Boolean"]>;
configurationParameters: Array<Maybe<ObjectPropertyInfo>>;
credentialParameters: Array<Maybe<AuthCredentialInfo>>;
};
@@ -940,8 +937,6 @@ export type GetAuthProvidersQuery = {
| "id"
| "displayName"
| "description"
| "editable"
| "identifying"
| "admin"
| "user"
| "possibleValues"
@@ -1653,8 +1648,6 @@ export const GetAuthProvidersDocument = gql`
id
displayName
description
editable
identifying
admin
user
possibleValues