Skip to content

Commit

Permalink
feat: exposing delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Apr 30, 2024
1 parent 8454854 commit b7c50aa
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 11 deletions.
10 changes: 10 additions & 0 deletions apps/consent/app/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ export type CurrencyConversionEstimation = {
readonly usdCentAmount: Scalars['CentAmount']['output'];
};

export type Delegation = {
readonly __typename: 'Delegation';
readonly app: Scalars['String']['output'];
readonly handledAt: Scalars['Timestamp']['output'];
readonly remember: Scalars['Boolean']['output'];
readonly scope: ReadonlyArray<Scalars['String']['output']>;
};

export type DepositFeesInformation = {
readonly __typename: 'DepositFeesInformation';
readonly minBankFee: Scalars['String']['output'];
Expand Down Expand Up @@ -1921,6 +1929,8 @@ export type User = {
readonly contacts: ReadonlyArray<UserContact>;
readonly createdAt: Scalars['Timestamp']['output'];
readonly defaultAccount: Account;
/** List of Oauth2 delegations */
readonly delegations: ReadonlyArray<Delegation>;
/** Email address */
readonly email?: Maybe<Email>;
readonly id: Scalars['ID']['output'];
Expand Down
22 changes: 22 additions & 0 deletions apps/dashboard/services/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ export type CurrencyConversionEstimation = {
readonly usdCentAmount: Scalars['CentAmount']['output'];
};

export type Delegation = {
readonly __typename: 'Delegation';
readonly app: Scalars['String']['output'];
readonly handledAt: Scalars['Timestamp']['output'];
readonly remember: Scalars['Boolean']['output'];
readonly scope: ReadonlyArray<Scalars['String']['output']>;
};

export type DepositFeesInformation = {
readonly __typename: 'DepositFeesInformation';
readonly minBankFee: Scalars['String']['output'];
Expand Down Expand Up @@ -2018,6 +2026,8 @@ export type User = {
readonly contacts: ReadonlyArray<UserContact>;
readonly createdAt: Scalars['Timestamp']['output'];
readonly defaultAccount: Account;
/** List of Oauth2 delegations */
readonly delegations: ReadonlyArray<Delegation>;
/** Email address */
readonly email?: Maybe<Email>;
readonly id: Scalars['ID']['output'];
Expand Down Expand Up @@ -3471,6 +3481,7 @@ export type ResolversTypes = {
CountryCode: ResolverTypeWrapper<Scalars['CountryCode']['output']>;
Currency: ResolverTypeWrapper<Currency>;
CurrencyConversionEstimation: ResolverTypeWrapper<CurrencyConversionEstimation>;
Delegation: ResolverTypeWrapper<Delegation>;
DepositFeesInformation: ResolverTypeWrapper<DepositFeesInformation>;
DeviceNotificationTokenCreateInput: DeviceNotificationTokenCreateInput;
DisplayCurrency: ResolverTypeWrapper<Scalars['DisplayCurrency']['output']>;
Expand Down Expand Up @@ -3699,6 +3710,7 @@ export type ResolversParentTypes = {
CountryCode: Scalars['CountryCode']['output'];
Currency: Currency;
CurrencyConversionEstimation: CurrencyConversionEstimation;
Delegation: Delegation;
DepositFeesInformation: DepositFeesInformation;
DeviceNotificationTokenCreateInput: DeviceNotificationTokenCreateInput;
DisplayCurrency: Scalars['DisplayCurrency']['output'];
Expand Down Expand Up @@ -4139,6 +4151,14 @@ export type CurrencyConversionEstimationResolvers<ContextType = any, ParentType
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type DelegationResolvers<ContextType = any, ParentType extends ResolversParentTypes['Delegation'] = ResolversParentTypes['Delegation']> = {
app?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
handledAt?: Resolver<ResolversTypes['Timestamp'], ParentType, ContextType>;
remember?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
scope?: Resolver<ReadonlyArray<ResolversTypes['String']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type DepositFeesInformationResolvers<ContextType = any, ParentType extends ResolversParentTypes['DepositFeesInformation'] = ResolversParentTypes['DepositFeesInformation']> = {
minBankFee?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
minBankFeeThreshold?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
Expand Down Expand Up @@ -4835,6 +4855,7 @@ export type UserResolvers<ContextType = any, ParentType extends ResolversParentT
contacts?: Resolver<ReadonlyArray<ResolversTypes['UserContact']>, ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['Timestamp'], ParentType, ContextType>;
defaultAccount?: Resolver<ResolversTypes['Account'], ParentType, ContextType>;
delegations?: Resolver<ReadonlyArray<ResolversTypes['Delegation']>, ParentType, ContextType>;
email?: Resolver<Maybe<ResolversTypes['Email']>, ParentType, ContextType>;
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
language?: Resolver<ResolversTypes['Language'], ParentType, ContextType>;
Expand Down Expand Up @@ -4992,6 +5013,7 @@ export type Resolvers<ContextType = any> = {
CountryCode?: GraphQLScalarType;
Currency?: CurrencyResolvers<ContextType>;
CurrencyConversionEstimation?: CurrencyConversionEstimationResolvers<ContextType>;
Delegation?: DelegationResolvers<ContextType>;
DepositFeesInformation?: DepositFeesInformationResolvers<ContextType>;
DisplayCurrency?: GraphQLScalarType;
Email?: EmailResolvers<ContextType>;
Expand Down
10 changes: 10 additions & 0 deletions apps/map/services/galoy/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ export type CurrencyConversionEstimation = {
readonly usdCentAmount: Scalars['CentAmount']['output'];
};

export type Delegation = {
readonly __typename: 'Delegation';
readonly app: Scalars['String']['output'];
readonly handledAt: Scalars['Timestamp']['output'];
readonly remember: Scalars['Boolean']['output'];
readonly scope: ReadonlyArray<Scalars['String']['output']>;
};

export type DepositFeesInformation = {
readonly __typename: 'DepositFeesInformation';
readonly minBankFee: Scalars['String']['output'];
Expand Down Expand Up @@ -1921,6 +1929,8 @@ export type User = {
readonly contacts: ReadonlyArray<UserContact>;
readonly createdAt: Scalars['Timestamp']['output'];
readonly defaultAccount: Account;
/** List of Oauth2 delegations */
readonly delegations: ReadonlyArray<Delegation>;
/** Email address */
readonly email?: Maybe<Email>;
readonly id: Scalars['ID']['output'];
Expand Down
10 changes: 10 additions & 0 deletions apps/pay/lib/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ export type CurrencyConversionEstimation = {
readonly usdCentAmount: Scalars['CentAmount'];
};

export type Delegation = {
readonly __typename: 'Delegation';
readonly app: Scalars['String'];
readonly handledAt: Scalars['Timestamp'];
readonly remember: Scalars['Boolean'];
readonly scope: ReadonlyArray<Scalars['String']>;
};

export type DepositFeesInformation = {
readonly __typename: 'DepositFeesInformation';
readonly minBankFee: Scalars['String'];
Expand Down Expand Up @@ -1920,6 +1928,8 @@ export type User = {
readonly contacts: ReadonlyArray<UserContact>;
readonly createdAt: Scalars['Timestamp'];
readonly defaultAccount: Account;
/** List of Oauth2 delegations */
readonly delegations: ReadonlyArray<Delegation>;
/** Email address */
readonly email?: Maybe<Email>;
readonly id: Scalars['ID'];
Expand Down
7 changes: 7 additions & 0 deletions bats/core/api/user.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ setup_file() {
language="$(graphql_output '.data.me.language')"
[[ "$language" == "$new_language" ]] || exit 1
}

@test "user: list sessions" {
exec_graphql 'alice' 'list-sessions'
sessions="$(graphql_output '.data.me.mobileSessions')"
id="$(echo "$sessions" | jq -r '.[0].id')" # Extracts the ID of the first element
[[ "$sessions" != "[]" ]] && [[ -n "$id" ]] || exit 1
}
6 changes: 6 additions & 0 deletions bats/gql/list-sessions.gql
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ query userDetails {
expiresAt
issuedAt
}
delegations {
app
handledAt
remember
scope
}
}
}
9 changes: 4 additions & 5 deletions core/api/src/app/users/list-sessions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { consentList } from "@/services/hydra"
import { listSessions as listSessionsService } from "@/services/kratos"

export const listMobileSessions = async (userId: UserId) => {
const list = await listSessionsService(userId)
console.dir(list)
return list
return listSessionsService(userId)
}

export const listDeleguateSessions = async (userId: UserId) => {

export const listDeleguations = async (userId: UserId) => {
return consentList(userId)
}
2 changes: 1 addition & 1 deletion core/api/src/domain/authentication/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type MobileSession = {
issuedAt: Date
}

type ConsentSession = {
type Delegation = {
scope: string[]
handledAt: Date
remember: boolean
Expand Down
10 changes: 10 additions & 0 deletions core/api/src/graphql/public/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ type CurrencyConversionEstimation {
usdCentAmount: CentAmount!
}

type Delegation {
app: String!
handledAt: Timestamp!
remember: Boolean!
scope: [String!]!
}

type DepositFeesInformation {
minBankFee: String!

Expand Down Expand Up @@ -1595,6 +1602,9 @@ type User {
createdAt: Timestamp!
defaultAccount: Account!

"""List of Oauth2 delegations"""
delegations: [Delegation!]!

"""Email address"""
email: Email
id: ID!
Expand Down
15 changes: 15 additions & 0 deletions core/api/src/graphql/public/types/object/deleguation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Timestamp from "@/graphql/shared/types/scalar/timestamp"

import { GT } from "@/graphql/index"

const Delegation = GT.Object({
name: "Delegation",
fields: () => ({
app: { type: GT.NonNull(GT.String) },
handledAt: { type: GT.NonNull(Timestamp) },
remember: { type: GT.NonNull(GT.Boolean) },
scope: { type: GT.NonNullList(GT.String) },
}),
})

export default Delegation
11 changes: 10 additions & 1 deletion core/api/src/graphql/public/types/object/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Account from "../abstract/account"

import SupportMessage from "./support-message"
import AccountContact from "./account-contact"
import Delegation from "./deleguation"

import { Accounts, Users, SupportChat } from "@/app"

Expand All @@ -19,7 +20,7 @@ import Language from "@/graphql/shared/types/scalar/language"
import Username from "@/graphql/shared/types/scalar/username"
import Timestamp from "@/graphql/shared/types/scalar/timestamp"
import GraphQLEmail from "@/graphql/shared/types/object/email"
import MobileSession from "./mobile-session"
import MobileSession from "@/graphql/public/types/object/mobile-session"

const GraphQLUser = GT.Object<User, GraphQLPublicContextAuth>({
name: "User",
Expand Down Expand Up @@ -84,6 +85,14 @@ const GraphQLUser = GT.Object<User, GraphQLPublicContextAuth>({
},
},

delegations: {
type: GT.NonNullList(Delegation),
description: "List of Oauth2 delegations",
resolve: async (source, args, { user }) => {
return Users.listDeleguations(user.id)
},
},

contacts: {
deprecationReason: "will be moved to account",
type: GT.NonNullList(AccountContact), // TODO: Make it a Connection Interface
Expand Down
6 changes: 4 additions & 2 deletions core/api/src/services/hydra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import axios, { AxiosResponse } from "axios"

const hydraUrl = process.env.HYDRA_ADMIN_URL || "http://localhost:4445"

export const consentList = async (userId: UserId): Promise<ConsentSession[]> => {
export const consentList = async (userId: UserId): Promise<Delegation[]> => {
/* eslint @typescript-eslint/ban-ts-comment: "off" */
// @ts-ignore-next-line no-implicit-any error
let res: AxiosResponse<any, any>

try {
Expand All @@ -15,7 +17,7 @@ export const consentList = async (userId: UserId): Promise<ConsentSession[]> =>
return []
}

let sessions: ConsentSession[]
let sessions: Delegation[]

try {
/* eslint @typescript-eslint/ban-ts-comment: "off" */
Expand Down
5 changes: 3 additions & 2 deletions core/api/test/integration/app/user/consent-list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { exec } from "child_process"
import puppeteer from "puppeteer"

import { Admin } from "@/app"
import { consentList } from "@/services/hydra"
import { sleep } from "@/utils"
import { exec } from "child_process"
import puppeteer from "puppeteer"

let userId: UserId
const email = "test@galoy.io" as EmailAddress
Expand Down
12 changes: 12 additions & 0 deletions dev/config/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ type CurrencyConversionEstimation
usdCentAmount: CentAmount!
}

type Delegation
@join__type(graph: PUBLIC)
{
app: String!
handledAt: Timestamp!
remember: Boolean!
scope: [String!]!
}

type DepositFeesInformation
@join__type(graph: PUBLIC)
{
Expand Down Expand Up @@ -2085,6 +2094,9 @@ type User
createdAt: Timestamp! @join__field(graph: PUBLIC)
defaultAccount: Account! @join__field(graph: PUBLIC)

"""List of Oauth2 delegations"""
delegations: [Delegation!]! @join__field(graph: PUBLIC)

"""Email address"""
email: Email @join__field(graph: PUBLIC)

Expand Down

0 comments on commit b7c50aa

Please sign in to comment.