@nextcloud/auth
Advanced tools
Comparing version 1.3.0 to 2.0.0
@@ -0,2 +1,4 @@ | ||
export type { CsrfTokenObserver } from './requesttoken'; | ||
export type { NextcloudUser } from './user'; | ||
export { getRequestToken, onRequestTokenUpdate } from './requesttoken'; | ||
export { getCurrentUser } from './user'; |
@@ -1,28 +0,56 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var eventBus = require('@nextcloud/event-bus'); | ||
var tokenElement = document.getElementsByTagName('head')[0]; | ||
var token = tokenElement ? tokenElement.getAttribute('data-requesttoken') : null; | ||
var observers = []; | ||
function getRequestToken() { | ||
return token; | ||
} | ||
function onRequestTokenUpdate(observer) { | ||
observers.push(observer); | ||
} | ||
// Listen to server event and keep token in sync | ||
eventBus.subscribe('csrf-token-update', function (e) { | ||
token = e.token; | ||
observers.forEach(function (observer) { | ||
try { | ||
observer(e.token); | ||
} | ||
catch (e) { | ||
console.error('error updating CSRF token observer', e); | ||
} | ||
}); | ||
}); | ||
Object.defineProperty(exports, "getRequestToken", { | ||
enumerable: true, | ||
get: function get() { | ||
return _requesttoken.getRequestToken; | ||
} | ||
}); | ||
Object.defineProperty(exports, "onRequestTokenUpdate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _requesttoken.onRequestTokenUpdate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getCurrentUser", { | ||
enumerable: true, | ||
get: function get() { | ||
return _user.getCurrentUser; | ||
} | ||
}); | ||
var _requesttoken = require("./requesttoken"); | ||
/// <reference types="@nextcloud/typings" /> | ||
var getAttribute = function (el, attribute) { | ||
if (el) { | ||
return el.getAttribute(attribute); | ||
} | ||
return null; | ||
}; | ||
var head = document.getElementsByTagName('head')[0]; | ||
var uid = getAttribute(head, 'data-user'); | ||
var displayName = getAttribute(head, 'data-user-displayname'); | ||
var isAdmin = (typeof OC === 'undefined') | ||
? false | ||
: OC.isUserAdmin(); | ||
function getCurrentUser() { | ||
if (uid === null) { | ||
return null; | ||
} | ||
return { | ||
uid: uid, | ||
displayName: displayName, | ||
isAdmin: isAdmin, | ||
}; | ||
} | ||
var _user = require("./user"); | ||
//# sourceMappingURL=index.js.map | ||
exports.getCurrentUser = getCurrentUser; | ||
exports.getRequestToken = getRequestToken; | ||
exports.onRequestTokenUpdate = onRequestTokenUpdate; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
interface CsrfTokenObserver { | ||
export interface CsrfTokenObserver { | ||
(token: string): void; | ||
@@ -6,2 +6,1 @@ } | ||
export declare function onRequestTokenUpdate(observer: CsrfTokenObserver): void; | ||
export {}; |
{ | ||
"name": "@nextcloud/auth", | ||
"version": "1.3.0", | ||
"description": "", | ||
"version": "2.0.0", | ||
"description": "Nextcloud helpers related to authentication and the current user", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.esm.js", | ||
"require": "./dist/index.js" | ||
}, | ||
"files": [ | ||
"dist/" | ||
], | ||
"scripts": { | ||
"build": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --source-maps && tsc --emitDeclarationOnly", | ||
"build:doc": "typedoc --out dist/doc lib && touch dist/doc/.nojekyll", | ||
"check-types": "tsc", | ||
"dev": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --watch", | ||
"build": "rollup --config rollup.config.js", | ||
"build:doc": "typedoc --out dist/doc lib/index.ts && touch dist/doc/.nojekyll", | ||
"check-types": "tsc --noEmit", | ||
"dev": "rollup --config rollup.config.js --watch", | ||
"test": "jest", | ||
@@ -26,21 +34,14 @@ "test:watch": "jest --watchAll" | ||
"dependencies": { | ||
"@nextcloud/event-bus": "^1.1.3", | ||
"@nextcloud/typings": "^0.2.2", | ||
"core-js": "^3.6.4" | ||
"@nextcloud/event-bus": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.0", | ||
"@babel/preset-typescript": "^7.9.0", | ||
"@nextcloud/browserslist-config": "^1.0.0", | ||
"babel-jest": "^26.0.1", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"jest": "^26.0.1", | ||
"typedoc": "^0.17.3", | ||
"typescript": "^3.8.3" | ||
}, | ||
"browserslist": [ | ||
"extends @nextcloud/browserslist-config" | ||
] | ||
"@nextcloud/typings": "^1.4.3", | ||
"@rollup/plugin-typescript": "^8.3.4", | ||
"jest": "^28.1.3", | ||
"jest-environment-jsdom": "^28.1.3", | ||
"rollup": "^2.77.2", | ||
"tslib": "^2.4.0", | ||
"typedoc": "^0.23.10", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
# @nextcloud/auth | ||
Nextcloud helpers related to authentication and the current user | ||
[![npm](https://img.shields.io/npm/v/@nextcloud/auth.svg)](https://www.npmjs.com/package/@nextcloud/auth) | ||
[![Documentation](https://img.shields.io/badge/Documentation-online-brightgreen)](https://nextcloud.github.io/nextcloud-auth/index.html) | ||
## Install | ||
```sh | ||
yarn add @nextcloud/auth | ||
``` | ||
```sh | ||
npm install @nextcloud/auth --save | ||
``` | ||
## Usage | ||
```ts | ||
import { | ||
getRequestToken, | ||
getCurrentUser, | ||
onRequestTokenUpdate, | ||
} from '@nextcloud/auth' | ||
const user = getCurrentUser() | ||
if (user.isAdmin) { | ||
// do something | ||
} | ||
``` | ||
For more imformation check [nextcloud.github.io/nextcloud-auth](https://nextcloud.github.io/nextcloud-auth/index.html) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
8
0
35
46897
10
113
+ Added@nextcloud/event-bus@3.3.1(transitive)
+ Added@types/node@20.17.7(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@nextcloud/typings@^0.2.2
- Removedcore-js@^3.6.4
- Removed@nextcloud/event-bus@1.3.0(transitive)
- Removed@nextcloud/typings@0.2.4(transitive)
- Removed@types/jquery@2.0.54(transitive)
- Removed@types/semver@7.5.8(transitive)
- Removedcore-js@3.39.0(transitive)
Updated@nextcloud/event-bus@^3.0.0