@@ -6,15 +6,16 @@ import { AuthActions } from '../store/auth'
6
6
import { Link } from 'react-router'
7
7
import { decodeToken } from 'jsontokens'
8
8
import {
9
- makeAuthResponse , getAuthRequestFromURL , Person , redirectUserToApp
9
+ makeAuthResponse , getAuthRequestFromURL , Person , redirectUserToApp ,
10
+ isLaterVersion
10
11
} from 'blockstack'
11
12
import Image from '../../components/Image'
12
13
import { AppsNode } from '../../utils/account-utils'
13
14
import { setCoreStorageConfig } from '../../utils/api-utils'
14
15
import { isCoreEndpointDisabled , isWindowsBuild } from '../../utils/window-utils'
15
16
import { getTokenFileUrlFromZoneFile } from '../../utils/zone-utils'
16
17
import { HDNode } from 'bitcoinjs-lib'
17
- import { validateScopes } from '../utils'
18
+ import { validateScopes , appRequestSupportsDirectHub } from '../utils'
18
19
import log4js from 'log4js'
19
20
20
21
const logger = log4js . getLogger ( 'auth/components/AuthModal.js' )
@@ -90,7 +91,7 @@ class AuthModal extends Component {
90
91
invalidScopes : false ,
91
92
sendEmail : false ,
92
93
blockchainId : null ,
93
- noStorage : false ,
94
+ noCoreStorage : false ,
94
95
responseSent : false ,
95
96
requestingEmail : false
96
97
}
@@ -139,7 +140,7 @@ class AuthModal extends Component {
139
140
const localIdentities = nextProps . localIdentities
140
141
const identityKeypairs = nextProps . identityKeypairs
141
142
if ( ( ! appDomain || ! nextProps . coreSessionTokens [ appDomain ] ) ) {
142
- if ( this . state . noStorage ) {
143
+ if ( this . state . noCoreStorage ) {
143
144
logger . debug ( 'componentWillReceiveProps: no core session token expected' )
144
145
} else {
145
146
logger . debug ( 'componentWillReceiveProps: no app domain or no core session token' )
@@ -151,7 +152,7 @@ class AuthModal extends Component {
151
152
152
153
const coreSessionToken = nextProps . coreSessionTokens [ appDomain ]
153
154
let decodedCoreSessionToken = null
154
- if ( ! this . state . noStorage ) {
155
+ if ( ! this . state . noCoreStorage ) {
155
156
logger . debug ( 'componentWillReceiveProps: received coreSessionToken' )
156
157
decodedCoreSessionToken = decodeToken ( coreSessionToken )
157
158
} else {
@@ -206,9 +207,6 @@ class AuthModal extends Component {
206
207
}
207
208
208
209
// TODO: what if the token is expired?
209
- // TODO: use a semver check -- or pass payload version to
210
- // makeAuthResponse
211
- let authResponse
212
210
213
211
let profileResponseData
214
212
if ( this . state . decodedToken . payload . do_not_include_profile ) {
@@ -217,19 +215,22 @@ class AuthModal extends Component {
217
215
profileResponseData = profile
218
216
}
219
217
220
- if ( this . state . decodedToken . payload . version === '1.1.0' &&
221
- this . state . decodedToken . payload . public_keys . length > 0 ) {
222
- const transitPublicKey = this . state . decodedToken . payload . public_keys [ 0 ]
218
+ let transitPublicKey = undefined
219
+ let hubUrl = undefined
223
220
224
- authResponse = makeAuthResponse ( privateKey , profileResponseData , blockchainId ,
225
- metadata ,
226
- coreSessionToken , appPrivateKey ,
227
- undefined , transitPublicKey )
228
- } else {
229
- authResponse = makeAuthResponse ( privateKey , profileResponseData , blockchainId ,
230
- metadata ,
231
- coreSessionToken , appPrivateKey )
221
+ const requestVersion = this . state . decodedToken . payload . version
222
+ if ( isLaterVersion ( requestVersion , '1.1.0' ) &&
223
+ this . state . decodedToken . payload . public_keys . length > 0 ) {
224
+ transitPublicKey = this . state . decodedToken . payload . public_keys [ 0 ]
232
225
}
226
+ if ( appRequestSupportsDirectHub ( this . state . decodedToken . payload ) ) {
227
+ hubUrl = this . props . api . gaiaHubConfig . server
228
+ }
229
+
230
+ const authResponse = makeAuthResponse ( privateKey , profileResponseData , blockchainId ,
231
+ metadata , coreSessionToken , appPrivateKey ,
232
+ undefined , transitPublicKey , hubUrl )
233
+
233
234
234
235
this . props . clearSessionToken ( appDomain )
235
236
@@ -304,6 +305,7 @@ class AuthModal extends Component {
304
305
const appsNode = new AppsNode ( HDNode . fromBase58 ( appsNodeKey ) , salt )
305
306
const appPrivateKey = appsNode . getAppNode ( appDomain ) . getAppPrivateKey ( )
306
307
const blockchainId = ( hasUsername ? identity . username : null )
308
+ const needsCoreStorage = ! appRequestSupportsDirectHub ( this . state . decodedToken . payload )
307
309
308
310
const scopesJSONString = JSON . stringify ( scopes )
309
311
@@ -320,7 +322,7 @@ class AuthModal extends Component {
320
322
sendEmail : ! ! scopes . includes ( 'email' )
321
323
} )
322
324
const requestingStoreWrite = ! ! scopes . includes ( 'store_write' )
323
- if ( requestingStoreWrite ) {
325
+ if ( requestingStoreWrite && needsCoreStorage ) {
324
326
logger . trace ( 'login(): Calling setCoreStorageConfig()...' )
325
327
setCoreStorageConfig ( this . props . api , identityIndex , identity . ownerAddress ,
326
328
identity . profile , profileSigningKeypair )
@@ -331,10 +333,16 @@ class AuthModal extends Component {
331
333
this . props . corePort , this . props . coreAPIPassword , appPrivateKey ,
332
334
appDomain , this . state . authRequest , blockchainId )
333
335
} )
336
+ } else if ( requestingStoreWrite && ! needsCoreStorage ) {
337
+ logger . trace ( 'login(): app can communicate directly with gaiahub, not setting up core.' )
338
+ this . setState ( {
339
+ noCoreStorage : true
340
+ } )
341
+ this . props . noCoreSessionToken ( appDomain )
334
342
} else {
335
343
logger . trace ( 'login(): No storage access requested.' )
336
344
this . setState ( {
337
- noStorage : true
345
+ noCoreStorage : true
338
346
} )
339
347
this . props . noCoreSessionToken ( appDomain )
340
348
}
@@ -347,14 +355,15 @@ class AuthModal extends Component {
347
355
const processing = this . state . processing
348
356
const invalidScopes = this . state . invalidScopes
349
357
const decodedToken = this . state . decodedToken
350
- const noStorage = ( decodedToken
351
- && decodedToken . payload . scopes
352
- && ! decodedToken . payload . scopes . includes ( 'store_write' ) )
358
+ const noCoreStorage = ( decodedToken
359
+ && decodedToken . payload . scopes
360
+ && ( ! decodedToken . payload . scopes . includes ( 'store_write' )
361
+ || appRequestSupportsDirectHub ( decodedToken . payload ) ) )
353
362
354
363
const coreShortCircuit = ( ! appManifestLoading
355
364
&& appManifest !== null
356
365
&& ! invalidScopes
357
- && ! noStorage
366
+ && ! noCoreStorage
358
367
&& isCoreEndpointDisabled ( ) )
359
368
if ( coreShortCircuit ) {
360
369
let appText
@@ -377,9 +386,19 @@ class AuthModal extends Component {
377
386
>
378
387
< h3 > Sign In Request</ h3 >
379
388
< div >
389
+ { appManifest . hasOwnProperty ( 'icons' ) ?
390
+ < p >
391
+ < Image
392
+ src = { appManifest . icons [ 0 ] . src }
393
+ style = { { width : '128px' , height : '128px' } }
394
+ fallbackSrc = "/images/app-icon-hello-blockstack.png"
395
+ />
396
+ </ p >
397
+ : null }
380
398
< p >
381
- This application requires using Gaia storage, which is not supported yet
382
- in our { appText } . Feature coming soon!
399
+ This application uses an older Gaia storage library, which is not supported
400
+ in our { appText } . Once the application updates its library, you will be
401
+ able to use it.
383
402
</ p >
384
403
</ div >
385
404
</ Modal >
0 commit comments