UNPKG

react-native-msal-client

Version:
61 lines (44 loc) 1.8 kB
'use strict'; var reactNative = require('react-native'); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const { RNMsalPlugin } = reactNative.NativeModules; const { MSALErrorCodes = {}, MSALUIBehavior } = RNMsalPlugin; const normalizeError = err => { if (reactNative.Platform.OS === 'ios' && err.code) { err.code = parseInt(err.code, 10); } throw err; }; class MsalClient { constructor(_authority, validate = false) { _defineProperty(this, "_authority", void 0); _defineProperty(this, "_validateAuthority", void 0); _defineProperty(this, "setAuthority", authority => { this._authority = authority; }); _defineProperty(this, "acquireTokenAsync", (clientId, scopes, redirectUri, userIdentitfier = null, uiBehavior = MSALUIBehavior.Default, extraQueryParameters = null) => RNMsalPlugin.acquireTokenAsync(this._authority, this._validateAuthority, clientId, scopes, redirectUri, userIdentitfier, uiBehavior, extraQueryParameters).catch(normalizeError)); _defineProperty(this, "acquireTokenSilentAsync", (clientId, scopes, userIdentitfier = null) => RNMsalPlugin.acquireTokenSilentAsync(this._authority, this._validateAuthority, clientId, scopes, userIdentitfier).catch(normalizeError)); _defineProperty(this, "tokenCacheDeleteItem", (clientId, userIdentitfier) => RNMsalPlugin.tokenCacheDeleteItem(this._authority, clientId, userIdentitfier).catch(normalizeError)); this._authority = _authority; this._validateAuthority = validate; } } _defineProperty(MsalClient, "ErrorCodes", MSALErrorCodes); module.exports = MsalClient;