@orello/auth 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/core/interfaces/config.d.ts +8 -0
- package/dist/core/interfaces/config.js +2 -0
- package/dist/core/interfaces/struct.d.ts +11 -0
- package/dist/core/interfaces/struct.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +23 -0
- package/dist/providers/auth.provider.d.ts +14 -0
- package/dist/providers/auth.provider.js +72 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Workstudio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @orello/auth
|
|
2
|
+
|
|
3
|
+
A lightweight, type-safe authentication provider for Orello applications. Built to simplify OAuth integration with Orello accounts.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Simple Redirect**: Easy-to-use method to initiate the Orello OAuth flow.
|
|
8
|
+
- **Token Exchange**: Standardized handling of authorization codes for access tokens.
|
|
9
|
+
- **User Info Retrieval**: Fetch authenticated user profiles with a single call.
|
|
10
|
+
- **TypeScript First**: Full type safety for authentication configurations and responses.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @orello/auth
|
|
16
|
+
# or
|
|
17
|
+
npm install @orello/auth
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Basic Configuration
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { OrelloAuthProvider } from "@orello/auth";
|
|
26
|
+
|
|
27
|
+
const auth = new OrelloAuthProvider({
|
|
28
|
+
clientKey: process.env.ORELLO_CLIENT_KEY,
|
|
29
|
+
clientSecret: process.env.ORELLO_CLIENT_SECRET, // Required for handleCallback
|
|
30
|
+
redirectUri: "https://your-app.com/callback",
|
|
31
|
+
scope: "openid profile email" // Optional
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Authentication Flow
|
|
36
|
+
|
|
37
|
+
#### 1. Redirect to Orello
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// This will redirect the user to Orello's login page
|
|
41
|
+
await auth.continueWithOrello();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### 2. Handle Callback
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// On your redirect page, get the 'code' from URL params
|
|
48
|
+
const code = new URLSearchParams(window.location.search).get("code");
|
|
49
|
+
|
|
50
|
+
if (code) {
|
|
51
|
+
const tokens = await auth.handleCallback(code);
|
|
52
|
+
console.log("Access Token:", tokens.access_token);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### 3. Get User Information
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const user = await auth.getUser(tokens.access_token);
|
|
60
|
+
console.log("Logged in user:", user.name);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
|
|
65
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to get involved.
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT © [HB Group](https://github.com/hb-group)
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.OrelloAuthProvider = void 0;
|
|
21
|
+
const auth_provider_1 = __importDefault(require("./providers/auth.provider"));
|
|
22
|
+
exports.OrelloAuthProvider = auth_provider_1.default;
|
|
23
|
+
__exportStar(require("./core/interfaces/config"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OrelloAuthConfig } from "../core/interfaces/config";
|
|
2
|
+
declare class OrelloAuthProvider {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
private clientKey;
|
|
5
|
+
private clientSecret;
|
|
6
|
+
private redirectUri;
|
|
7
|
+
private scope;
|
|
8
|
+
private state;
|
|
9
|
+
constructor(options: OrelloAuthConfig);
|
|
10
|
+
continueWithOrello(): Promise<string>;
|
|
11
|
+
handleCallback(code: string): Promise<any>;
|
|
12
|
+
getUser(accessToken: string): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
export default OrelloAuthProvider;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class OrelloAuthProvider {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.baseUrl = "https://accounts.orello.space/o/oauth/auth";
|
|
15
|
+
if (!options.clientKey)
|
|
16
|
+
throw new Error("Client Key was not provided.");
|
|
17
|
+
if (!options.redirectUri)
|
|
18
|
+
throw new Error("Redirect URI was not provided.");
|
|
19
|
+
this.clientKey = options.clientKey;
|
|
20
|
+
this.clientSecret = options.clientSecret || "";
|
|
21
|
+
this.redirectUri = options.redirectUri;
|
|
22
|
+
this.scope = options.scope || "openid profile email";
|
|
23
|
+
this.state = options.state || Math.random().toString(36).substring(7);
|
|
24
|
+
}
|
|
25
|
+
continueWithOrello() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const url = `${this.baseUrl}?client_id=${this.clientKey}&redirect_uri=${encodeURIComponent(this.redirectUri)}&response_type=code&scope=${encodeURIComponent(this.scope)}&state=${this.state}`;
|
|
28
|
+
if (typeof window !== "undefined") {
|
|
29
|
+
window.location.href = url;
|
|
30
|
+
}
|
|
31
|
+
return url;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
handleCallback(code) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (!this.clientSecret) {
|
|
37
|
+
throw new Error("Client Secret is required for token exchange.");
|
|
38
|
+
}
|
|
39
|
+
const response = yield fetch("https://accounts.orello.space/o/oauth/token", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
43
|
+
},
|
|
44
|
+
body: new URLSearchParams({
|
|
45
|
+
grant_type: "authorization_code",
|
|
46
|
+
code,
|
|
47
|
+
client_id: this.clientKey,
|
|
48
|
+
client_secret: this.clientSecret,
|
|
49
|
+
redirect_uri: this.redirectUri,
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
throw new Error("Failed to exchange token");
|
|
54
|
+
}
|
|
55
|
+
return yield response.json();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
getUser(accessToken) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const response = yield fetch("https://accounts.orello.space/o/oauth/userinfo", {
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${accessToken}`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new Error("Failed to fetch user info");
|
|
67
|
+
}
|
|
68
|
+
return yield response.json();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = OrelloAuthProvider;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orello/auth",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Authentication package for Orello.",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
|
|
14
|
+
"build": "tsc -p tsconfig.json",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"auth",
|
|
20
|
+
"oauth",
|
|
21
|
+
"orello",
|
|
22
|
+
"authentication"
|
|
23
|
+
],
|
|
24
|
+
"author": "Workstudio",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/hb-group/orello.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/hb-group/orello/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/hb-group/orello#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"dotenv": "^16.6.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^20.0.0",
|
|
39
|
+
"nodemon": "^3.1.0",
|
|
40
|
+
"ts-node": "^10.9.2",
|
|
41
|
+
"typescript": "^5.9.2"
|
|
42
|
+
}
|
|
43
|
+
}
|