Smart M.App discussions

Looking for answers in regards to M.Apps, M.App Exchange or M.App Studio? Smart M.App Tech Discussion board is where you can search, ask your questions and assist others by sharing your knowledge. Join the conversation, connect, contribute and share.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Frequent Contributor
Posts: 107
Registered: ‎10-16-2015

invalid JSON

I’ve made this script that runs just fine standalone, accessing M.App Chest using OAuth.

Now I’m trying to run it from the Studio and I get this error message out of nowhere saying ‘Uncaught SyntaxError: Unexpected end of JSON input’

 

In the debugger I find this JSON-string:

 

{"storageKey":"__state_gXqzmta00JeNKSQi","csrfZeton":"mWWS1NpYqRIdHrvKvKOzQGdGoV7pZYxKrDJ6lvhzpaPvvoZ7xvRYpJCMtPfwABSH","fragment":"access_token=eyJhbGciOiJSUzI1NiJ9.eyJjb21wYW55X2lkIjoiZjgwMjdmYTctNjZiZi00Y2U5LWE5YzMtNjI5NGMxYzAzYzU2IiwidXNlcl9uYW1lIjoiMWYxYjNlNjYtYWQ2Ni00NDE0LWEwNmYtZTA1MDhlMjE0ZTFkIiwic2NRjVFTp_wyu4ycm6JaAFzzLI9iI9AC40AvKweZAVuOPqvcn0Hu6nphKUjSXgOcsSNk1JG19K7oZRjRUATMd4raEtHJ1ecfHt_mo0Ar6-oagL9PXoyb912R_epArmW6D_36wAcyQIJ7INsslxV_C6oGRdwGoEtQturBPLOKux1IyUs5AGA8GvMAdPijTPp3XVbXRVEh5Up7yrAtMtR0luuSg"

 

Indeed, this does not look right.

 

My question: do you have any idea what may cause this?? I don’t see this response in any network-requests (then again, not all results are shown)

 

This is the pretty-printed code:

 

function() {

    var t = function(t, e) {

        return function() {

            return t.apply(e, arguments)

        }

    };

    define("windmill-app-builder-common/core/authorizationStrategies/UrlBasedStrategy", ["lodash", "urijs", "when"], function(e, n, r) {

        var i;

        return i = function() {

            function r(e) {

                this.__secretsKeeper = e,

                this.authorize = t(this.authorize, this),

                this.__checkIfArgumentsAreValid(this.__secretsKeeper)

            }

            return r.prototype.authorize = function() {

                var t, r, i, o, s, a;

                if (a = new n,

                r = new n("?" + a.fragment()).query(!0),

                t = r.access_token,

                o = r.state,

                i = r.organization_id,

                null != a && null != t && null != o) {

 

                 // this is the line where the error occurs

 

                    if (s = e.isString(o) ? JSON.parse(o) : o,

                    !this.__secretsKeeper.verifyState(s))

                        throw new Error("InvalidState: Invalid state detected; possible CSRF");

                    return this.__secretsKeeper.setToken(t),

                    this.__secretsKeeper.setOrganizationId(i),

                    a.fragment(s.fragment),

                    window.history.replaceState(null, null, a.href())

                }

            }

            ,

            r.prototype.__checkIfArgumentsAreValid = function(t) {

                if (null == t)

                    throw new Error("InvalidArgument: secretsKeeper cannot be null");

                if (!e.isFunction(t.setToken))

                    throw new Error("InvalidArgument: secretsKeeper must have setToken method")

            }

            ,

            r

        }()

    })

}

Highlighted
Frequent Contributor
Posts: 107
Registered: ‎10-16-2015

Re: invalid JSON

[ Edited ]

keep getting this error.

 

In the examples below I've sometimes changed keys and user-id's for obvious reasons

 

So somewhere in the code in the neighbourhood of this line:

define("windmill-app-builder-common/core/authorizationStrategies/UrlBasedStrategy", ["lodash", "urijs", "when"], 

 there's an object 'a' that appears to be location.href

 

it gets parsed in this code:

if (a = new n,
r = new n("?" + a.fragment()).query(!0),
t = r.access_token,
o = r.state,
i = r.organization_id,
null != a && null != t && null != o) {
if (s = e.isString(o) ? JSON.parse(o) : o,
!this.__secretsKeeper.verifyState(s))
throw new Error("InvalidState: Invalid state detected; possible CSRF");
return this.__secretsKeeper.setToken(t),
this.__secretsKeeper.setOrganizationId(i),
a.fragment(s.fragment),
window.history.replaceState(null, null, a.href())
}

 

looking into 'r' I see 2 client_ids: my app and 'smart-mapp-studio-19762'. Looks good

r.username: [
  '1f1b3e66-ad66-a06f-e0508e214e"}",
  '1f1b3e66-ad66-a06f-e0508e214e'
]

 

r.state:

"{"storageKey":"__state_DSSs7M08VQN1Ah2Hu0Ev","csrfZeton":"c9muampql4O6eTeaXMajoI7MVaFVRqnxV2c42XX7abvdyMmT27WjnpXM9Ye7t","fragment":"access_token=eyJhbGciOiJS_AOtRO3ZMQjaG6FR1eyDqf255xPan5nLRwuIVBlA_u1koGn7uAIxuDJ7cJyx7uXwjp0vo35uXGLxzgVSf7cNbVhP4Xh4RlBb9wN1ZspONRjVFTp_wyu4ycm6JaAFzzLI9iI9AC40AvKweZAVuOPqvcn0Hu6nphKUjSXgOcsSNk1JG19K7oZRjRUATMd4raEtHJ1ecfHt_mo0Ar6-oagL9PXoyb912R_epArmW6D_36wAcyQIJ7INsslxV_C6oGRdwGoEtQturBPLOKux1IyUs5AGA8GvMAdPijTPp3XVbXRVEh5Up7yrAtMtR0luuSg"

 

So this is where things go sour, because this is not valid JSON.

 

Could it be that a.fragment() is truncated because it is too long?

 

The original a.fragment() is this:

 

access_token=eyJhbGciOiJSLARGECHUNKREMOVED1gwJRvVmjGp76m2N_PtieIA4qW22td9rMRjJtUA&token_type=bearer&state=%7B%22storageKey%22:%22__state_DSSs7M08VQN1Ah2Hu0Ev%22,%22csrfZeton%22:%22c9muampql4O60KUeTeaXMajoI7MVaFVRqnxV2c42XXREMOVEDYe7t%22,%22fragment%22:%22access_token=eyJLARGECHUNKSREMOVEDrAtMtR0luuSg&token_type=bearer&expires_in=4090132&scope=&client_id=configurator-142004&username=1f1b3e66-ad66-a06f-e0508e214e1d%22%7D&expires_in=3231295&scope=&client_id=smart-mapp-studio-19672&username=1f1b3e66-ad66-4414-a06f-e054e1d

 

Highlighted
Frequent Contributor
Posts: 107
Registered: ‎10-16-2015

Re: invalid JSON

Could I maybe send my custom code to someone from Hexagon with access to the original code? So they can replicate this issue?

I've run out of ideas here