Socket
Socket
Sign inDemoInstall

@wix/api-client

Package Overview
Dependencies
Maintainers
18
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wix/api-client - npm Package Compare versions

Comparing version 1.1.36 to 1.1.37

64

dist/cjs/auth/OAuthStrategy.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;

@@ -7,7 +8,10 @@ exports.OAuthStrategy = OAuthStrategy;

var _identity = require("@wix/identity");
var _redirectsApi = require("@wix/redirects-api");
var _tokenHelpers = require("../tokenHelpers");
var _pkceChallenge = _interopRequireDefault(require("pkce-challenge"));
function OAuthStrategy(config) {
const wixClient = (0, _wixClient.createClient)({
modules: {
oauth: _identity.oauth
oauth: _identity.oauth,
redirects: _redirectsApi.redirects
}

@@ -24,2 +28,11 @@ });

};
let wixClientWithTokens = (0, _wixClient.createClient)({
modules: {
oauth: _identity.oauth,
redirects: _redirectsApi.redirects
},
headers: {
Authorization: _tokens.accessToken.value
}
});
const generateVisitorTokens = async tokens => {

@@ -54,5 +67,46 @@ var _tokens$accessToken, _tokens$refreshToken, _tokens$refreshToken2;

};
const generateOauthRedirectState = async origin => {
const state = {
origin
};
const pkceState = (0, _pkceChallenge.default)();
return {
...state,
codeChallenge: pkceState.code_challenge,
codeVerifier: pkceState.code_verifier
};
};
const signInWithRedirect = async state => {
const {
redirectSession
} = await wixClientWithTokens.redirects.authorizeUrl({
redirectUri: state.origin,
clientId: config.clientId,
codeChallenge: state.codeChallenge,
codeChallengeMethod: 'S256',
responseMode: 'fragment',
responseType: 'code',
scope: 'openid email',
state: window.crypto.randomUUID().split('-')[0]
});
window.location.href = redirectSession == null ? void 0 : redirectSession.fullUrl;
};
const setTokens = tokens => {
_tokens.accessToken = tokens.accessToken;
_tokens.refreshToken = tokens.refreshToken;
wixClientWithTokens = (0, _wixClient.createClient)({
modules: {
oauth: _identity.oauth,
redirects: _redirectsApi.redirects
},
headers: {
Authorization: _tokens.accessToken.value
}
});
};
return {
generateVisitorTokens,
renewToken,
signInWithRedirect,
generateOauthRedirectState,
getAuthHeaders: async () => {

@@ -64,4 +118,3 @@ var _tokens$accessToken2;

});
_tokens.accessToken = tokens.accessToken;
_tokens.refreshToken = tokens.refreshToken;
setTokens(tokens);
}

@@ -74,6 +127,3 @@ return Promise.resolve({

},
setTokens: tokens => {
_tokens.accessToken = tokens.accessToken;
_tokens.refreshToken = tokens.refreshToken;
},
setTokens,
getTokens: () => _tokens

@@ -80,0 +130,0 @@ };

import { createClient } from '../wixClient';
import { oauth } from '@wix/identity';
import { redirects } from '@wix/redirects-api';
import { createAccessToken, isTokenExpired } from '../tokenHelpers';
import pkceChallenge from 'pkce-challenge';
export function OAuthStrategy(config) {
const wixClient = createClient({
modules: {
oauth
oauth,
redirects
}

@@ -19,2 +22,11 @@ });

};
let wixClientWithTokens = createClient({
modules: {
oauth,
redirects
},
headers: {
Authorization: _tokens.accessToken.value
}
});
const generateVisitorTokens = async tokens => {

@@ -49,5 +61,46 @@ var _tokens$accessToken, _tokens$refreshToken, _tokens$refreshToken2;

};
const generateOauthRedirectState = async origin => {
const state = {
origin
};
const pkceState = pkceChallenge();
return {
...state,
codeChallenge: pkceState.code_challenge,
codeVerifier: pkceState.code_verifier
};
};
const signInWithRedirect = async state => {
const {
redirectSession
} = await wixClientWithTokens.redirects.authorizeUrl({
redirectUri: state.origin,
clientId: config.clientId,
codeChallenge: state.codeChallenge,
codeChallengeMethod: 'S256',
responseMode: 'fragment',
responseType: 'code',
scope: 'openid email',
state: window.crypto.randomUUID().split('-')[0]
});
window.location.href = redirectSession == null ? void 0 : redirectSession.fullUrl;
};
const setTokens = tokens => {
_tokens.accessToken = tokens.accessToken;
_tokens.refreshToken = tokens.refreshToken;
wixClientWithTokens = createClient({
modules: {
oauth,
redirects
},
headers: {
Authorization: _tokens.accessToken.value
}
});
};
return {
generateVisitorTokens,
renewToken,
signInWithRedirect,
generateOauthRedirectState,
getAuthHeaders: async () => {

@@ -59,4 +112,3 @@ var _tokens$accessToken2;

});
_tokens.accessToken = tokens.accessToken;
_tokens.refreshToken = tokens.refreshToken;
setTokens(tokens);
}

@@ -69,6 +121,3 @@ return Promise.resolve({

},
setTokens: tokens => {
_tokens.accessToken = tokens.accessToken;
_tokens.refreshToken = tokens.refreshToken;
},
setTokens,
getTokens: () => _tokens

@@ -75,0 +124,0 @@ };

@@ -13,2 +13,7 @@ export interface Tokens {

}
export interface OauthRedirectState {
origin: string;
codeVerifier: string;
codeChallenge: string;
}
export interface IOAuthStrategy extends AuthenticationStrategy {

@@ -22,2 +27,4 @@ generateVisitorTokens(tokens?: {

getTokens: () => Tokens;
generateOauthRedirectState: (origin: string) => Promise<OauthRedirectState>;
signInWithRedirect: (state: OauthRedirectState) => Promise<any>;
}

@@ -24,0 +31,0 @@ export declare function OAuthStrategy(config: {

22

package.json
{
"name": "@wix/api-client",
"version": "1.1.36",
"version": "1.1.37",
"license": "UNLICENSED",

@@ -31,5 +31,7 @@ "author": {

"@babel/runtime": "^7.21.0",
"@wix/identity": "^1.0.18",
"@wix/image-kit": "^1.30.0",
"@wix/sdk-types": "^1.1.36",
"@wix/identity": "^1.0.22",
"@wix/image-kit": "^1.31.0",
"@wix/redirects-api": "^1.0.17",
"@wix/sdk-types": "^1.1.37",
"pkce-challenge": "^3.0.0",
"querystring": "^0.2.1",

@@ -40,7 +42,7 @@ "type-fest": "^2.19.0"

"@types/jest": "^27.5.2",
"@types/node": "^16.18.14",
"@wix/ecom": "^1.0.125",
"@wix/events": "^1.0.52",
"@wix/jest-yoshi-preset": "^6.51.2",
"@wix/yoshi-flow-library": "^6.51.2",
"@types/node": "^16.18.20",
"@wix/ecom": "^1.0.136",
"@wix/events": "^1.0.70",
"@wix/jest-yoshi-preset": "^6.53.0",
"@wix/yoshi-flow-library": "^6.53.0",
"ts-jest": "^27.1.5",

@@ -72,3 +74,3 @@ "typescript": "~4.9.5"

},
"falconPackageHash": "8728011015ddef0256b1d4ddb89d01011bbcfe7adf5d3f43b24ad34c"
"falconPackageHash": "520c99325ff8b20f766ad250f1505d08d1437a5e6e23ff9a65cdada2"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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