Skip to content

Commit

Permalink
feat: glee auth v2 (#474)
Browse files Browse the repository at this point in the history
Co-authored-by: Khuda Dad Nomani <[email protected]>
  • Loading branch information
oviecodes and KhudaDad414 authored Aug 21, 2023
1 parent d83701d commit f761154
Show file tree
Hide file tree
Showing 38 changed files with 1,629 additions and 151 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage
.github
examples
node_modules
docs
2 changes: 2 additions & 0 deletions docs/reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
- [lib/message](modules/lib_message.md)
- [lib/router](modules/lib_router.md)
- [lib/servers](modules/lib_servers.md)
- [lib/userAuth](modules/lib_userAuth.md)
- [lib/util](modules/lib_util.md)
- [lib/wsHttpAuth](modules/lib_wsHttpAuth.md)
- [middlewares](modules/middlewares.md)
- [middlewares/buffer2string](modules/middlewares_buffer2string.md)
- [middlewares/errorLogger](modules/middlewares_errorLogger.md)
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/classes/lib_glee.default.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ Adds a connection adapter.
| :------ | :------ |
| `Adapter` | typeof [`default`](lib_adapter.default.md) |
| `«destructured»` | `Object` |
| `parsedAsyncAPI` | `AsyncAPIDocument` |
| `server` | `Server` |
| `serverName` | `string` |
| `parsedAsyncAPI` | `AsyncAPIDocument` |
| `server` | `Server` |
| `serverName` | `string` |

#### Returns

Expand Down
12 changes: 12 additions & 0 deletions docs/reference/interfaces/lib.HttpAuthConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@

### Properties

- [password](lib.HttpAuthConfig.md#password)
- [token](lib.HttpAuthConfig.md#token)
- [username](lib.HttpAuthConfig.md#username)

## Properties

### password

`Optional` **password**: `string`

#### Defined in

[src/lib/index.d.ts:35](https://github.com/oviecodes/glee/blob/2283982/src/lib/index.d.ts#L35)

___

### token

`Optional` **token**: `string`
Expand Down
22 changes: 22 additions & 0 deletions docs/reference/interfaces/lib.WsAuthConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,36 @@

### Properties

- [password](lib.WsAuthConfig.md#password)
- [token](lib.WsAuthConfig.md#token)
- [username](lib.WsAuthConfig.md#username)

## Properties

### password

`Optional` **password**: `string`

#### Defined in

[src/lib/index.d.ts:29](https://github.com/oviecodes/glee/blob/2283982/src/lib/index.d.ts#L29)

___

### token

`Optional` **token**: `string`

#### Defined in

[src/lib/index.d.ts:27](https://github.com/asyncapi/glee/blob/b84101b/src/lib/index.d.ts#L27)

___

### username

`Optional` **username**: `string`

#### Defined in

[src/lib/index.d.ts:28](https://github.com/oviecodes/glee/blob/2283982/src/lib/index.d.ts#L28)
4 changes: 4 additions & 0 deletions docs/reference/modules/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
### Type Aliases

- [AuthFunction](lib.md#authfunction)
- [AuthProps](lib.md#authprops)
- [CoreGleeConfig](lib.md#coregleeconfig)
- [GleeAuthFunction](lib.md#gleeauthfunction)
- [GleeAuthFunctionEvent](lib.md#gleeauthfunctionevent)
- [GleeClusterAdapterConfig](lib.md#gleeclusteradapterconfig)
- [GleeConfig](lib.md#gleeconfig)
- [GleeFunction](lib.md#gleefunction)
Expand All @@ -30,6 +33,7 @@
- [QueryParam](lib.md#queryparam)
- [WebSocketServerType](lib.md#websocketservertype)
- [WebsocketAdapterConfig](lib.md#websocketadapterconfig)
- [WsHttpAuth](lib.md#wshttpauth)

## Type Aliases

Expand Down
20 changes: 20 additions & 0 deletions docs/reference/modules/lib_adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@

### Type Aliases

- [AuthEvent](lib_adapter.md#authevent)
- [EnrichedEvent](lib_adapter.md#enrichedevent)

## Type Aliases

### AuthEvent

Ƭ **AuthEvent**: `Object`

#### Type declaration

| Name | Type |
| :------ | :------ |
| `authProps` | [`AuthProps`](lib.md#authprops) |
| `callback` | `any` |
| `doc` | `any` |
| `serverName` | `string` |

#### Defined in

[src/lib/adapter.ts:17](https://github.com/oviecodes/glee/blob/2283982/src/lib/adapter.ts#L17)

___

### EnrichedEvent

Ƭ **EnrichedEvent**: `Object`
Expand Down
85 changes: 85 additions & 0 deletions docs/reference/modules/lib_userAuth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[@asyncapi/glee](../README.md) / lib/userAuth

# Module: lib/userAuth

## Table of contents

### Variables

- [authFunctions](lib_userAuth.md#authfunctions)

### Functions

- [clientAuthConfig](lib_userAuth.md#clientauthconfig)
- [register](lib_userAuth.md#register)
- [triggerAuth](lib_userAuth.md#triggerauth)

## Variables

### authFunctions

`Const` **authFunctions**: `Map`<`string`, `AuthFunctionInfo`\>

#### Defined in

[src/lib/userAuth.ts:15](https://github.com/oviecodes/glee/blob/2283982/src/lib/userAuth.ts#L15)

## Functions

### clientAuthConfig

**clientAuthConfig**(`serverName`): `Promise`<[`GleeAuthFunction`](lib.md#gleeauthfunction)\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `serverName` | `string` |

#### Returns

`Promise`<[`GleeAuthFunction`](lib.md#gleeauthfunction)\>

#### Defined in

[src/lib/userAuth.ts:79](https://github.com/oviecodes/glee/blob/2283982/src/lib/userAuth.ts#L79)

___

### register

**register**(`dir`): `Promise`<`void`[]\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `dir` | `string` |

#### Returns

`Promise`<`void`[]\>

#### Defined in

[src/lib/userAuth.ts:17](https://github.com/oviecodes/glee/blob/2283982/src/lib/userAuth.ts#L17)

___

### triggerAuth

**triggerAuth**(`params`): `Promise`<`void`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `params` | [`GleeAuthFunctionEvent`](lib.md#gleeauthfunctionevent) |

#### Returns

`Promise`<`void`\>

#### Defined in

[src/lib/userAuth.ts:49](https://github.com/oviecodes/glee/blob/2283982/src/lib/userAuth.ts#L49)
9 changes: 9 additions & 0 deletions docs/reference/modules/lib_wsHttpAuth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[@asyncapi/glee](../README.md) / lib/wsHttpAuth

# Module: lib/wsHttpAuth

## Table of contents

### Classes

- [default](../classes/lib_wsHttpAuth.default.md)
3 changes: 3 additions & 0 deletions examples/anime-http/client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TOKEN=arb-valueFromClientAuth
OAUTH2=arb-OAUTH_access_token
APIKEY=arb-APIKEY_token
37 changes: 37 additions & 0 deletions examples/anime-http/client/asyncapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ servers:
trendingAnime:
url: http://localhost:8081
protocol: http
security:
- token: []
- userPass: []
- apiKey: []
- UserOrPassKey: []
- oauth:
- write:pets
- read:pets
testwebhook:
url: ws://localhost:9000
protocol: ws
Expand Down Expand Up @@ -43,3 +51,32 @@ components:
summary: ping client
payload:
type: object
securitySchemes:
token:
type: http
scheme: bearer
bearerFormat: JWT
userPass:
type: userPassword
apiKey:
type: httpApiKey
name: api_key
in: query
UserOrPassKey:
type: apiKey
in: user
oauth:
type: oauth2
flows:
implicit:
authorizationUrl: https://example.com/api/oauth/dialog
scopes:
write:pets: modify pets in your account
read:pets: read your pets
authorizationCode:
authorizationUrl: https://example.com/api/oauth/dialog
tokenUrl: https://example.com/api/oauth/dialog
scopes:
delete:pets: modify pets in your account
update:pets: read your pets

15 changes: 15 additions & 0 deletions examples/anime-http/client/auth/trendingAnime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-undef */

export async function clientAuth({ serverName }) {
console.log("serverName", serverName)

return {
token: process.env.TOKEN,
oauth: process.env.OAUTH2,
apiKey: process.env.APIKEY,
userPass: {
user: process.env.USERNAME,
password: process.env.PASSWORD
}
}
}
Loading

0 comments on commit f761154

Please sign in to comment.