From 8d0919a231c5c63e1de254672ff3df541221fd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cosmin=20P=C3=A2rvulescu?= Date: Mon, 20 Nov 2023 15:45:56 +0200 Subject: [PATCH] chore(galaxy): Scope resolver (#2761) --- packages/galaxy-client/gql/apps.graphql | 10 --- packages/galaxy-client/index.ts | 51 ------------- platform/galaxy/src/schema/index.ts | 3 +- platform/galaxy/src/schema/resolvers/app.ts | 74 ------------------- platform/galaxy/src/schema/resolvers/index.ts | 3 +- platform/galaxy/src/schema/types/app.ts | 14 ---- platform/galaxy/src/schema/types/index.ts | 3 +- 7 files changed, 3 insertions(+), 155 deletions(-) delete mode 100644 packages/galaxy-client/gql/apps.graphql delete mode 100644 platform/galaxy/src/schema/resolvers/app.ts delete mode 100644 platform/galaxy/src/schema/types/app.ts diff --git a/packages/galaxy-client/gql/apps.graphql b/packages/galaxy-client/gql/apps.graphql deleted file mode 100644 index 49be26c758..0000000000 --- a/packages/galaxy-client/gql/apps.graphql +++ /dev/null @@ -1,10 +0,0 @@ -query getAuthorizedAppScopes($clientId: String!) { - scopes(clientId: $clientId) { - permission - scopes - } -} - -mutation revokeAppAuthorization($clientId: String!) { - revokeAppAuthorization(clientId: $clientId) -} diff --git a/packages/galaxy-client/index.ts b/packages/galaxy-client/index.ts index 64deda19e4..bd7714a18c 100644 --- a/packages/galaxy-client/index.ts +++ b/packages/galaxy-client/index.ts @@ -49,7 +49,6 @@ export type Mutation = { __typename?: 'Mutation'; disconnectAccount?: Maybe; registerSessionKey: Scalars['String']; - revokeAppAuthorization?: Maybe; updateAccountNickname?: Maybe; updateConnectedAccountsProperties?: Maybe; }; @@ -66,11 +65,6 @@ export type MutationRegisterSessionKeyArgs = { }; -export type MutationRevokeAppAuthorizationArgs = { - clientId: Scalars['String']; -}; - - export type MutationUpdateAccountNicknameArgs = { accountURN: Scalars['String']; nickname: Scalars['String']; @@ -126,7 +120,6 @@ export type Query = { connectedAccounts?: Maybe>; identityFromAlias: Scalars['String']; profile?: Maybe; - scopes: Array>; }; @@ -155,17 +148,6 @@ export type QueryProfileArgs = { targetIdentityURN?: InputMaybe; }; - -export type QueryScopesArgs = { - clientId: Scalars['String']; -}; - -export type Scope = { - __typename?: 'Scope'; - permission: Scalars['String']; - scopes: Array>; -}; - export type StandardPfp = { __typename?: 'StandardPFP'; image?: Maybe; @@ -208,20 +190,6 @@ export type UpdateConnectedAccountsPropertiesMutationVariables = Exact<{ export type UpdateConnectedAccountsPropertiesMutation = { __typename?: 'Mutation', updateConnectedAccountsProperties?: boolean | null }; -export type GetAuthorizedAppScopesQueryVariables = Exact<{ - clientId: Scalars['String']; -}>; - - -export type GetAuthorizedAppScopesQuery = { __typename?: 'Query', scopes: Array<{ __typename?: 'Scope', permission: string, scopes: Array } | null> }; - -export type RevokeAppAuthorizationMutationVariables = Exact<{ - clientId: Scalars['String']; -}>; - - -export type RevokeAppAuthorizationMutation = { __typename?: 'Mutation', revokeAppAuthorization?: boolean | null }; - export type GetProfileQueryVariables = Exact<{ targetIdentityURN?: InputMaybe; }>; @@ -286,19 +254,6 @@ export const UpdateConnectedAccountsPropertiesDocument = gql` updateConnectedAccountsProperties(accountURNList: $accountURNList) } `; -export const GetAuthorizedAppScopesDocument = gql` - query getAuthorizedAppScopes($clientId: String!) { - scopes(clientId: $clientId) { - permission - scopes - } -} - `; -export const RevokeAppAuthorizationDocument = gql` - mutation revokeAppAuthorization($clientId: String!) { - revokeAppAuthorization(clientId: $clientId) -} - `; export const GetProfileDocument = gql` query getProfile($targetIdentityURN: String) { profile(targetIdentityURN: $targetIdentityURN) { @@ -362,12 +317,6 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = updateConnectedAccountsProperties(variables: UpdateConnectedAccountsPropertiesMutationVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(UpdateConnectedAccountsPropertiesDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'updateConnectedAccountsProperties', 'mutation'); }, - getAuthorizedAppScopes(variables: GetAuthorizedAppScopesQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { - return withWrapper((wrappedRequestHeaders) => client.request(GetAuthorizedAppScopesDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAuthorizedAppScopes', 'query'); - }, - revokeAppAuthorization(variables: RevokeAppAuthorizationMutationVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { - return withWrapper((wrappedRequestHeaders) => client.request(RevokeAppAuthorizationDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'revokeAppAuthorization', 'mutation'); - }, getProfile(variables?: GetProfileQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetProfileDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getProfile', 'query'); }, diff --git a/platform/galaxy/src/schema/index.ts b/platform/galaxy/src/schema/index.ts index 0b562c170e..64ad51d3eb 100644 --- a/platform/galaxy/src/schema/index.ts +++ b/platform/galaxy/src/schema/index.ts @@ -3,7 +3,7 @@ import { mergeTypeDefs } from '@graphql-tools/merge' import GraphQLJSON from 'graphql-type-json' import types from './types' -import { accountResolver, appResolver, identityResolver } from './resolvers' +import { accountResolver, identityResolver } from './resolvers' import { GalaxyServerContext } from '..' const mergedTypes = mergeTypeDefs(types) @@ -12,7 +12,6 @@ export default createSchema({ typeDefs: mergedTypes, resolvers: [ accountResolver, - appResolver, identityResolver, { JSON: GraphQLJSON, diff --git a/platform/galaxy/src/schema/resolvers/app.ts b/platform/galaxy/src/schema/resolvers/app.ts deleted file mode 100644 index 36909554f6..0000000000 --- a/platform/galaxy/src/schema/resolvers/app.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { composeResolvers } from '@graphql-tools/resolvers-composition' -import { ResolverContext } from './common' -import type { Resolvers } from './typedefs' -import { - validateApiKey, - isAuthorized, - logAnalytics, - requestLogging, - setupContext, -} from './utils' -import createCoreClient from '@proofzero/platform-clients/core' -import { getAuthzHeaderConditionallyFromToken } from '@proofzero/utils' -import { generateTraceContextHeaders } from '@proofzero/platform-middleware/trace' -import core from '@proofzero/platform-clients/core' - -const appResolvers: Resolvers = { - Query: { - scopes: async ( - _parent: any, - { clientId }, - { env, identityURN, traceSpan }: ResolverContext - ) => { - const coreClient = createCoreClient( - env.Core, - generateTraceContextHeaders(traceSpan) - ) - - const scopes = - await coreClient.authorization.getAuthorizedAppScopes.query({ - identityURN, - clientId, - }) - - return scopes.claimValues - }, - }, - Mutation: { - revokeAppAuthorization: async ( - _parent: any, - { clientId }, - { env, jwt, traceSpan }: ResolverContext - ) => { - const coreClient = createCoreClient(env.Core, { - ...getAuthzHeaderConditionallyFromToken(jwt), - ...generateTraceContextHeaders(traceSpan), - }) - - await coreClient.authorization.revokeAppAuthorization.mutate({ - clientId, - }) - - return true - }, - }, -} - -const AppResolverComposition = { - 'Query.scopes': [ - requestLogging(), - setupContext(), - validateApiKey(), - isAuthorized(), - logAnalytics(), - ], - 'Mutation.revokeAppAuthorization': [ - requestLogging(), - setupContext(), - validateApiKey(), - isAuthorized(), - logAnalytics(), - ], -} - -export default composeResolvers(appResolvers, AppResolverComposition) diff --git a/platform/galaxy/src/schema/resolvers/index.ts b/platform/galaxy/src/schema/resolvers/index.ts index f88a67f695..c88b1b55d2 100644 --- a/platform/galaxy/src/schema/resolvers/index.ts +++ b/platform/galaxy/src/schema/resolvers/index.ts @@ -1,5 +1,4 @@ import identityResolver from './identity' import accountResolver from './account' -import appResolver from './app' -export { identityResolver, accountResolver, appResolver } +export { identityResolver, accountResolver } diff --git a/platform/galaxy/src/schema/types/app.ts b/platform/galaxy/src/schema/types/app.ts deleted file mode 100644 index 638c1935a3..0000000000 --- a/platform/galaxy/src/schema/types/app.ts +++ /dev/null @@ -1,14 +0,0 @@ -export default /* GraphQL */ ` - type Scope { - permission: String! - scopes: [String]! - } - - type Query { - scopes(clientId: String!): [Scope]! - } - - type Mutation { - revokeAppAuthorization(clientId: String!): Boolean - } -` diff --git a/platform/galaxy/src/schema/types/index.ts b/platform/galaxy/src/schema/types/index.ts index b1a1abe699..10529a6fcc 100644 --- a/platform/galaxy/src/schema/types/index.ts +++ b/platform/galaxy/src/schema/types/index.ts @@ -2,6 +2,5 @@ import common from './common' import edges from './edges' import account from './account' import identity from './identity' -import app from './app' -export default [common, edges, account, identity, app] +export default [common, edges, account, identity]