node.js - 401 Authorization Required integrating Hyperledger Composer REST API from Webapp -
introduction
i have hyperledger env running in secure mode following link https://hyperledger.github.io/composer/integrating/enabling-rest-authentication.html
and works fine if authenticate specified in document (hitting http://mydomain:3000/auth/github
directly browser) , access rest api http://mydomain:3000/explorer
, authorize various participants (i.e, issuing identity , adding them wallet , setting 1 default @ time) , see assets per .acl file.
issue
but started facing problems when started integrating rest api's from web application rather directly browser. first step from web app, called http://mydomain:3000/auth/github
authenticate , started calling other apis (transaction/list, etc.) error 401: 'authorization required'
what have tried
gave web application url 'redirect url' in env variable hyperledger. , upon successful authentication (calling http://mydomain:3000/auth/github
) redirected webapp home page afterwards accessing rest api's (from web app) again throws 'authorization required' error.
environment variaable below:
export composer_providers='{ "github": { "provider": "github", "module": "passport-github", "clientid": "client_id", "clientsecret": "client_secret", "authpath": "/auth/github", "callbackurl": "/auth/github/callback", "successredirect": "http://localhost:8080/home.html", "failureredirect": "/" } }'
incorporated passport-github2
mechanism in web application (i.e, registered app oauth of github) , upon successful login web application; called http://mydomain:3000/auth/github
authenticate blockchain , did not work out well.
i have few questions:
- is feasible call secured hyperledger rest api's web application?
- if yes, how it? don't find information in hyperledger composer documentation.
have been trying week , have no answers. appreciated. please let me know if unclear. thanks.
i commented problem on 1 of existing hyperledger github issues(below link) & want share solution solved problem me. https://github.com/hyperledger/composer/issues/142
solution: mentioned user sstone1
since rest server on different port number web application, need specify additional option http client pass cookies rest server. using angular http client, add
withcredentials
flag, example:
via angular:
this.http.get('http://mydomain:3000/api/myasset', { withcredentials: true })
via jquery ajax:
$.ajax({ url: 'http://mydomain:3000/api/myasset', xhrfields: { withcredentials: true }, headers: { ... } })
Comments
Post a Comment