Socket
Socket
Sign inDemoInstall

oidc-react

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oidc-react - npm Package Compare versions

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

40

build/src/AuthContext.d.ts

@@ -8,44 +8,11 @@ import React, { FC } from 'react';

export interface AuthProviderProps {
/**
* See [UserManager](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) for more details.
*/
userManager?: UserManager;
/**
* The URL of the OIDC/OAuth2 provider.
*/
authority?: string;
/**
* Your client application's identifier as registered with the OIDC/OAuth2 provider.
*/
clientId?: string;
/**
* The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider.
*/
redirectUri?: string;
/**
* Tells the authorization server which grant to execute
*
* Read more: https://tools.ietf.org/html/rfc6749#section-3.1.1
*/
responseType?: string;
/**
* A space-delimited list of permissions that the application requires.
*/
scope?: string;
/**
* Defaults to `windows.location`.
*/
location?: Location;
/**
* defaults to true
*/
autoSignIn?: boolean;
/**
* On sign out hook. Can be a async function.
* @param userData User
*/
onSignIn?: (userData: User | null) => Promise<void>;
/**
* On sign out hook. Can be a async function.
*/
onSignOut?: () => Promise<void>;

@@ -56,12 +23,5 @@ }

signOut: () => void;
/**
* See [User](https://github.com/IdentityModel/oidc-client-js/wiki#user) for more details.
*/
userData?: User | null;
}
export declare const AuthContext: React.Context<AuthContextProps>;
/**
*
* @param props AuthProviderProps
*/
export declare const AuthProvider: FC<AuthProviderProps>;

64

build/src/AuthContext.js

@@ -1,18 +0,32 @@

import React, { useState, useEffect } from 'react';
import { UserManager } from 'oidc-client';
export const AuthContext = React.createContext({
signIn: /* istanbul ignore next */ () => { },
signOut: /* istanbul ignore next */ () => { },
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const oidc_client_1 = require("oidc-client");
exports.AuthContext = react_1.default.createContext({
signIn: () => { },
signOut: () => { },
});
/**
*
* @param props AuthProviderProps
*/
export const AuthProvider = (props) => {
exports.AuthProvider = (props) => {
const { children, autoSignIn = true, onSignIn, onSignOut, location = window.location, } = props;
let { userManager } = props;
const [userData, setUserData] = useState(null);
const [userData, setUserData] = react_1.useState(null);
if (!userManager) {
const { authority, clientId, redirectUri, responseType, scope, } = props;
userManager = new UserManager({
userManager = new oidc_client_1.UserManager({
authority,

@@ -28,12 +42,10 @@ client_id: clientId,

}
/* istanbul ignore next */
if (!userManager) {
// This should never happen.
throw new Error('UserManager is missing.');
}
const signIn = async () => {
const signIn = () => __awaiter(void 0, void 0, void 0, function* () {
userManager && userManager.signinRedirect();
};
useEffect(() => {
const getUser = async () => {
});
react_1.useEffect(() => {
const getUser = () => __awaiter(void 0, void 0, void 0, function* () {
const searchParams = new URLSearchParams(location.search);

@@ -47,4 +59,4 @@ const hashParams = new URLSearchParams(location.hash.replace('#', '?'));

hashParams.get('session_state')) {
await userManager.signinRedirectCallback();
const user = await userManager.getUser();
yield userManager.signinRedirectCallback();
const user = yield userManager.getUser();
setUserData(user);

@@ -54,3 +66,3 @@ onSignIn && onSignIn(user);

}
const user = await userManager.getUser();
const user = yield userManager.getUser();
if ((!user || user === null) && autoSignIn) {

@@ -63,3 +75,3 @@ signIn();

return;
};
});
getUser();

@@ -69,10 +81,10 @@ }, [location]);

signIn,
signOut: async () => {
await userManager.removeUser();
signOut: () => __awaiter(void 0, void 0, void 0, function* () {
yield userManager.removeUser();
setUserData(null);
onSignOut && onSignOut();
},
}),
userData,
};
return (React.createElement(AuthContext.Provider, { value: context }, children));
return (react_1.default.createElement(exports.AuthContext.Provider, { value: context }, children));
};

@@ -1,2 +0,7 @@

export * from './AuthContext';
export * from './useAuth';
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./AuthContext"));
__export(require("./useAuth"));

@@ -1,6 +0,7 @@

/* eslint @typescript-eslint/explicit-function-return-type: 0 */
import { useContext } from 'react';
import { AuthContext } from './AuthContext';
export const useAuth = () => {
return useContext(AuthContext);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const AuthContext_1 = require("./AuthContext");
exports.useAuth = () => {
return react_1.useContext(AuthContext_1.AuthContext);
};

@@ -6,2 +6,9 @@ # Changelog

# [1.0.0-alpha.3](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2020-04-09)
### Bug Fixes
* Package size and target ([b9c8205](https://github.com/bjerkio/oidc-react/commit/b9c820524cd34f030d823af867df3d51ad2d2bd7))
# [1.0.0-alpha.2](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2020-04-09)

@@ -8,0 +15,0 @@

{
"name": "oidc-react",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"private": false,

@@ -12,3 +12,3 @@ "description": "",

"start": "node build/index.js",
"build": "tsc",
"build": "tsc -p tsconfig.release.json",
"test": "jest --coverage src --passWithNoTests",

@@ -15,0 +15,0 @@ "test:watch": "npm run test -- --watch",

@@ -63,2 +63,3 @@ # OIDC React

- [Guides](guides/)
- [Example repository](https://github.com/cobraz/example-react-oidc)
- [oidc-client-js Documentation](https://github.com/IdentityModel/oidc-client-js/wiki)

@@ -65,0 +66,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc