@cambridge-pte/adonisjs6-gigya
v1.0.0
Published
Gigya integration for AdonisJS v6 applications
Keywords
Readme
AdonisJS Gigya Package
Gigya integration for AdonisJS v6 applications
This package provides seamless integration with Gigya's Customer Identity Access Management (CIAM) platform for AdonisJS applications. It includes a service provider, type definitions, and a convenient service wrapper for easy usage throughout your application.
Installation
Install the package using your preferred package manager:
npm install @cambridge-pte/adonisjs6-gigyayarn add @cambridge-pte/adonisjs6-gigyapnpm add @cambridge-pte/adonisjs6-gigyaInstall Gigya SDK (Required for TypeScript)
If you plan to create service wrappers with TypeScript support, you'll also need to install the Gigya SDK for type definitions:
npm install gigya@npm:@cambridge-pte/gigya@^3.0.5yarn add gigya@npm:@cambridge-pte/gigya@^3.0.5pnpm add gigya@npm:@cambridge-pte/gigya@^3.0.5Note: The Gigya SDK is already included as a dependency in this package for runtime usage. You only need to install it separately if you want TypeScript type definitions in your service wrappers.
Configuration
1. Register the Provider
Add the Gigya provider to your adonisrc.ts file:
import { defineConfig } from '@adonisjs/core/app'
export default defineConfig({
// ...other configuration
providers: [
// ...other providers
() => import('@cambridge-pte/adonisjs6-gigya/gigya_provider'),
],
})2. Create Configuration File
Create a configuration file at config/gigya.ts:
import { defineConfig } from '@adonisjs/core/app'
import env from '#start/env'
const gigyaConfig = defineConfig({
/**
* Gigya API key
*/
apiKey: env.get('GIGYA_API_KEY'),
//...rest
})
export default gigyaConfig3. Environment Variables
Add the required environment variables to your .env file:
GIGYA_API_KEY=your_gigya_api_key
GIGYA_DATA_CENTER=us1
GIGYA_SECRET=your_gigya_secret
# OR for user key authentication:
# GIGYA_USER_KEY=your_user_key
# GIGYA_SECRET_KEY=your_secret_key
# OR for RSA authentication:
# GIGYA_RSA_USER_KEY=your_rsa_user_key
# GIGYA_RSA_PRIVATE_KEY=your_rsa_private_key
# Optional settings
GIGYA_TIMEOUT=10000
GIGYA_DEBUG=falseUsage
Direct Container Access
You can access the Gigya instance directly from the IoC container:
import app from '@adonisjs/core/services/app'
// In a controller, service, or other class
const gigya = await app.container.make('gigya')
const response = await gigya.accounts.getAccountInfo({ UID: 'user-id' })Service Wrapper (Recommended)
Create a service wrapper for easier usage throughout your application. Create the file app/services/gigya/main.ts:
import app from '@adonisjs/core/services/app'
import { Gigya } from 'gigya'
let gigya: Gigya
await app.booted(async () => {
gigya = await app.container.make('gigya')
})
export { gigya as default }Using the Service in Controllers
import { HttpContext } from '@adonisjs/core/http'
import gigya from '#services/gigya/main'
export default class AuthController {
async search({ request, response }: HttpContext) {
const { email } = request.all()
try {
const result = await gigya.accounts.search({
query: `SELECT * FROM accounts where profile.email=${email}`,
})
return response.json({ success: true, data: result })
} catch (error) {
return response.status(400).json({
success: false,
error: error.message,
})
}
}
}Authentication Methods
The package supports three authentication methods with Gigya:
Secret-based Authentication
// config/gigya.ts
export default defineConfig({
apiKey: 'your_api_key',
dataCenter: 'us1',
secret: 'your_secret_key',
})User Key Authentication
// config/gigya.ts
export default defineConfig({
apiKey: 'your_api_key',
dataCenter: 'us1',
userKey: 'your_user_key',
secretKey: 'your_secret_key',
})RSA Authentication
// config/gigya.ts
export default defineConfig({
apiKey: 'your_api_key',
dataCenter: 'us1',
rsa: {
userKey: 'your_rsa_user_key',
privateKey: 'your_rsa_private_key',
},
})API Reference
The service wrapper provides direct access to the Gigya instance. Once imported, you can use any Gigya SDK method:
import gigya from '#services/gigya/main'
// Use any Gigya SDK method
await gigya.accounts.getAccountInfo({ UID: 'user-id' })
await gigya.accounts.register({ email: '[email protected]', password: 'password' })
await gigya.accounts.login({ loginID: '[email protected]', password: 'password' })
await gigya.accounts.logout({ UID: 'user-id' })For the complete Gigya API, refer to the official Gigya documentation.
License
MIT
