Socket
Socket
Sign inDemoInstall

expo-auth-session

Package Overview
Dependencies
Maintainers
20
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-auth-session - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

src/__tests__/ManagedSessionUrlProvider-test.ts

4

.expo/tsconfig.jest.json
{
"extends": "/Users/bbarthec/Work/expo/packages/expo-auth-session/tsconfig.json",
"extends": "/Users/brentvatne/code/expo/packages/expo-auth-session/tsconfig.json",
"compilerOptions": {

@@ -10,5 +10,5 @@ "module": "esnext",

"../../../node_modules/@types",
"/Users/bbarthec/Work/expo/packages/expo-module-scripts/ts-declarations"
"/Users/brentvatne/code/expo/packages/expo-module-scripts/ts-declarations"
]
}
}

@@ -45,3 +45,3 @@ import { openAuthSessionAsync, dismissAuthSession } from 'expo-web-browser';

}
let { params, errorCode } = parseUrl(result.url);
const { params, errorCode } = parseUrl(result.url);
return {

@@ -65,3 +65,3 @@ type: errorCode ? 'error' : 'success',

// $FlowIssue: Flow thinks the awaited result can be a promise
let result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });
const result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });
if (result.type === 'cancel' || result.type === 'dismiss') {

@@ -73,10 +73,10 @@ return { type: result.type };

function parseUrl(url) {
let parts = url.split('#');
let hash = parts[1];
let partsWithoutHash = parts[0].split('?');
let queryString = partsWithoutHash[partsWithoutHash.length - 1];
const parts = url.split('#');
const hash = parts[1];
const partsWithoutHash = parts[0].split('?');
const queryString = partsWithoutHash[partsWithoutHash.length - 1];
// Get query string (?hello=world)
let parsedSearch = qs.parse(queryString);
const parsedSearch = qs.parse(queryString);
// Pull errorCode off of params
let { errorCode } = parsedSearch;
const { errorCode } = parsedSearch;
delete parsedSearch.errorCode;

@@ -89,3 +89,3 @@ // Get hash (#abc=example)

// Merge search and hash
let params = {
const params = {
...parsedSearch,

@@ -92,0 +92,0 @@ ...parsedHash,

@@ -6,8 +6,6 @@ import { SessionUrlProvider } from './SessionUrlProvider';

private static readonly USES_CUSTOM_SCHEME;
private static readonly HOST_URI;
private static readonly IS_EXPO_HOSTED;
getDefaultReturnUrl(): string;
getDefaultReturnUrl(urlPath?: string): string;
getStartUrl(authUrl: string, returnUrl: string): string;
getRedirectUrl(): string;
static getHostUri(): string;
private static getHostAddress;
private static warnIfAnonymous;

@@ -14,0 +12,0 @@ private static removeScheme;

@@ -5,6 +5,10 @@ import Constants from 'expo-constants';

export class ManagedSessionUrlProvider {
getDefaultReturnUrl() {
getDefaultReturnUrl(urlPath) {
const hostAddress = ManagedSessionUrlProvider.getHostAddress();
const isExpoHosted = hostAddress.hostUri &&
(/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(hostAddress.hostUri) ||
manifest.developer);
let scheme = 'exp';
let path = ManagedSessionUrlProvider.SESSION_PATH;
let manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);
const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);
if (Constants.appOwnership === 'standalone' && manifestScheme) {

@@ -19,8 +23,8 @@ scheme = manifestScheme;

}
let hostUri = ManagedSessionUrlProvider.HOST_URI || '';
if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) {
let hostUri = hostAddress.hostUri || '';
if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && isExpoHosted) {
hostUri = '';
}
if (path) {
if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) {
if (isExpoHosted && hostUri) {
path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`;

@@ -35,7 +39,17 @@ }

}
if (urlPath) {
path = [path, urlPath].filter(Boolean).join('/');
}
let { parameters } = hostAddress;
if (parameters) {
parameters = `?${parameters}`;
}
else {
parameters = '';
}
hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri);
return encodeURI(`${scheme}://${hostUri}${path}`);
return encodeURI(`${scheme}://${hostUri}${path}${parameters}`);
}
getStartUrl(authUrl, returnUrl) {
let queryString = qs.stringify({
const queryString = qs.stringify({
authUrl,

@@ -53,4 +67,4 @@ returnUrl,

}
static getHostUri() {
let hostUri = manifest.hostUri;
static getHostAddress() {
let hostUri = Constants.manifest.hostUri;
if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) {

@@ -61,3 +75,8 @@ // we're probably not using up-to-date xdl, so just fake it for now

}
return hostUri;
const uriParts = hostUri?.split('?');
const parameters = uriParts?.[1];
if (uriParts?.length > 0) {
hostUri = uriParts[0];
}
return { hostUri, parameters };
}

@@ -82,6 +101,2 @@ static warnIfAnonymous(id, url) {

ManagedSessionUrlProvider.USES_CUSTOM_SCHEME = Constants.appOwnership === 'standalone' && manifest.scheme;
ManagedSessionUrlProvider.HOST_URI = ManagedSessionUrlProvider.getHostUri();
ManagedSessionUrlProvider.IS_EXPO_HOSTED = ManagedSessionUrlProvider.HOST_URI &&
(/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(ManagedSessionUrlProvider.HOST_URI) ||
manifest.developer);
//# sourceMappingURL=ManagedSessionUrlProvider.js.map
{
"name": "expo-auth-session",
"version": "1.0.0",
"version": "1.0.1",
"description": "Expo module for browser-based authentication",

@@ -38,3 +38,3 @@ "main": "build/AuthSession.js",

"expo-constants": "~9.0.0",
"expo-web-browser": "~8.1.0"
"expo-web-browser": "~8.1.1"
},

@@ -47,3 +47,3 @@ "devDependencies": {

},
"gitHead": "3ad68bbd9847ebc8a55272c263b17d998a92f64f"
"gitHead": "2f1fb3daa49eca6b03e903a45db312bbfe3e4b5c"
}

@@ -64,3 +64,3 @@ import Constants from 'expo-constants';

let parallelStartAsyncCalls = Promise.all([
const parallelStartAsyncCalls = Promise.all([
AuthSession.startAsync({ authUrl, returnUrl }),

@@ -72,3 +72,3 @@ AuthSession.startAsync({ authUrl, returnUrl }),

let [first, second] = await parallelStartAsyncCalls;
const [first, second] = await parallelStartAsyncCalls;
expect(first).toEqual(normalResponse);

@@ -85,3 +85,3 @@ expect(second).toEqual(lockedResponse);

let authSessionPromise = AuthSession.startAsync({
const authSessionPromise = AuthSession.startAsync({
authUrl,

@@ -91,3 +91,3 @@ returnUrl,

emitLinkingEvent('url', { url: returnUrlWithParams });
let result = await authSessionPromise;
const result = await authSessionPromise;

@@ -103,3 +103,3 @@ expect(result.type).toEqual('success');

const returnUrl = 'https://example-return.io/+';
let authSessionPromise = AuthSession.startAsync({
const authSessionPromise = AuthSession.startAsync({
authUrl,

@@ -112,3 +112,3 @@ returnUrl,

let result = await authSessionPromise;
const result = await authSessionPromise;
expect(result.type).toEqual('error');

@@ -138,3 +138,3 @@ expect((result as any).errorCode).toEqual('nope');

let authSessionPromise = AuthSession.startAsync({
const authSessionPromise = AuthSession.startAsync({
authUrl,

@@ -145,3 +145,3 @@ returnUrl,

let result = await authSessionPromise;
const result = await authSessionPromise;

@@ -148,0 +148,0 @@ expect(result.type).not.toEqual('locked');

@@ -58,3 +58,3 @@ import { openAuthSessionAsync, dismissAuthSession } from 'expo-web-browser';

let { params, errorCode } = parseUrl(result.url);
const { params, errorCode } = parseUrl(result.url);

@@ -83,3 +83,3 @@ return {

// $FlowIssue: Flow thinks the awaited result can be a promise
let result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });
const result = await openAuthSessionAsync(startUrl, returnUrl, { showInRecents });
if (result.type === 'cancel' || result.type === 'dismiss') {

@@ -93,12 +93,12 @@ return { type: result.type };

function parseUrl(url: string): { errorCode: string | null; params: { [key: string]: string } } {
let parts = url.split('#');
let hash = parts[1];
let partsWithoutHash = parts[0].split('?');
let queryString = partsWithoutHash[partsWithoutHash.length - 1];
const parts = url.split('#');
const hash = parts[1];
const partsWithoutHash = parts[0].split('?');
const queryString = partsWithoutHash[partsWithoutHash.length - 1];
// Get query string (?hello=world)
let parsedSearch = qs.parse(queryString);
const parsedSearch = qs.parse(queryString);
// Pull errorCode off of params
let { errorCode } = parsedSearch;
const { errorCode } = parsedSearch;
delete parsedSearch.errorCode;

@@ -113,3 +113,3 @@

// Merge search and hash
let params = {
const params = {
...parsedSearch,

@@ -116,0 +116,0 @@ ...parsedHash,

@@ -13,14 +13,15 @@ import Constants from 'expo-constants';

Constants.appOwnership === 'standalone' && manifest.scheme;
private static readonly HOST_URI = ManagedSessionUrlProvider.getHostUri();
private static readonly IS_EXPO_HOSTED =
ManagedSessionUrlProvider.HOST_URI &&
(/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(
ManagedSessionUrlProvider.HOST_URI
) ||
manifest.developer);
getDefaultReturnUrl(): string {
getDefaultReturnUrl(urlPath?: string): string {
const hostAddress = ManagedSessionUrlProvider.getHostAddress();
const isExpoHosted =
hostAddress.hostUri &&
(/^(.*\.)?(expo\.io|exp\.host|exp\.direct|expo\.test)(:.*)?(\/.*)?$/.test(
hostAddress.hostUri
) ||
manifest.developer);
let scheme = 'exp';
let path = ManagedSessionUrlProvider.SESSION_PATH;
let manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);
const manifestScheme = manifest.scheme || (manifest.detach && manifest.detach.scheme);

@@ -39,4 +40,4 @@ if (Constants.appOwnership === 'standalone' && manifestScheme) {

let hostUri = ManagedSessionUrlProvider.HOST_URI || '';
if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && ManagedSessionUrlProvider.IS_EXPO_HOSTED) {
let hostUri = hostAddress.hostUri || '';
if (ManagedSessionUrlProvider.USES_CUSTOM_SCHEME && isExpoHosted) {
hostUri = '';

@@ -46,3 +47,3 @@ }

if (path) {
if (ManagedSessionUrlProvider.IS_EXPO_HOSTED && hostUri) {
if (isExpoHosted && hostUri) {
path = `/--/${ManagedSessionUrlProvider.removeLeadingSlash(path)}`;

@@ -58,9 +59,19 @@ }

if (urlPath) {
path = [path, urlPath].filter(Boolean).join('/');
}
let { parameters } = hostAddress;
if (parameters) {
parameters = `?${parameters}`;
} else {
parameters = '';
}
hostUri = ManagedSessionUrlProvider.removeTrailingSlash(hostUri);
return encodeURI(`${scheme}://${hostUri}${path}`);
return encodeURI(`${scheme}://${hostUri}${path}${parameters}`);
}
getStartUrl(authUrl: string, returnUrl: string): string {
let queryString = qs.stringify({
const queryString = qs.stringify({
authUrl,

@@ -81,4 +92,4 @@ returnUrl,

static getHostUri(): string {
let hostUri = manifest.hostUri;
private static getHostAddress(): { hostUri: string; parameters: string | undefined } {
let hostUri: string = Constants.manifest.hostUri;
if (!hostUri && !ManagedSessionUrlProvider.USES_CUSTOM_SCHEME) {

@@ -93,3 +104,9 @@ // we're probably not using up-to-date xdl, so just fake it for now

return hostUri;
const uriParts = hostUri?.split('?');
const parameters = uriParts?.[1];
if (uriParts?.length > 0) {
hostUri = uriParts[0];
}
return { hostUri, parameters };
}

@@ -116,2 +133,2 @@

}
}
}

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