Commit 10a2f86d authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg

Minor update. Update on how to reference JSO import

parent 7672d489
Pipeline #6918 failed with stages
in 4 minutes and 17 seconds
......@@ -5,5 +5,6 @@
```
./install-fonts.sh
npm i
npm run dev
npm start
```
This diff is collapsed.
......@@ -4,7 +4,7 @@
"version": "0.1.0",
"main": "",
"scripts": {
"start": "node server",
"start": "node server",
"dev": "webpack-dev-server --content-base public --config ./webpack.dev.config.js --host 0.0.0.0 ",
"build": "webpack --display-error-details -d",
"build:prod": "webpack -p --config ./webpack.prod.config.js"
......@@ -34,6 +34,7 @@
},
"dependencies": {
"axios": "^0.16.2",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-polyfill": "^6.23.0",
"bootstrap": "^3.3.7",
"dotenv": "^4.0.0",
......
......@@ -54,11 +54,13 @@ if (q.embedded) {
}
if (q.callback && q.callback === 'dataporten') {
console.error(' CALLBACK (dataporten)')
store.dispatch(API.callback(q.callback))
}
store.dispatch(API.authenticate())
.then(() => {
if (q.callback && q.callback === 'orcid' && q.code) {
console.error(' CALLBACK (orcid)', window.location.pathname)
window.history.replaceState(null, null, window.location.pathname)
store.dispatch(API.callbackCode(q.code))
}
......
......@@ -29,9 +29,7 @@ const reducer = handleActions({
}
}),
completed: (state, action) => {
console.error(" ORCID FETCHING COMPLETED,", action.payload)
if (action.error) {
console.error("ERROR ORCID LIST LOADING", action)
return {
...state,
orcids: {
......
import actions from '../actions/'
import jso from '../../lib/jso'
// import jso from '../../lib/jso'
import {JSO, Popup} from 'jso'
const baseURL = 'https://prefstore.dataporten-api.no'
class Authenticator {
constructor(jsoconfig) {
this.jso = new jso(jsoconfig)
this.jso = new JSO(jsoconfig)
}
authenticateORCID() {
let opts = {
response_type: 'code'
}
console.log("AUTHENTICATE authenticateORCIDauthenticateORCIDauthenticateORCIDauthenticateORCIDauthenticateORCID", this.jso.config.config.providerID)
this.jso.wipeTokens()
return this.jso.getToken((token) => {
console.log("SO the ORCID Token is " , token)
return {}
}, opts)
return this.jso.getToken({})
.then((token) => {
return {}
})
}
authenticate() {
let opts = {}
// console.log("AUTHENTICATE", this.jso.config.config.providerID)
return this.jso.getToken((token) => {
let fetchConfig = {"headers": {}}
fetchConfig.headers.Authorization = 'Bearer ' + token.access_token
fetchConfig.method = "GET"
fetchConfig.mode = "cors"
return fetch(this.jso.config.config.userinfo, fetchConfig).then((response) => {
if (response.ok) {
return response.json()
}
throw Error(response.statusText)
})
.then((userinfo) => {
return [userinfo, token]
return this.jso.getToken(opts)
.then((token) => {
// console.error("Get Token returned ", token)
let fetchConfig = {"headers": {}}
fetchConfig.headers.Authorization = 'Bearer ' + token.access_token
fetchConfig.method = "GET"
fetchConfig.mode = "cors"
return fetch(this.jso.config.config.userinfo, fetchConfig).then((response) => {
if (response.ok) {
return response.json()
}
throw Error(response.statusText)
})
// console.error("Got token, ayay", token)
// dispatch(actions.tokens.save(token))
}, opts)
.then((userinfo) => {
return [userinfo, token]
})
// console.error("Got token, ayay", token)
// dispatch(actions.tokens.save(token))
})
}
callback() {
......@@ -51,7 +49,6 @@ class Authenticator {
})
}
}
const authDataporten = new Authenticator({
......@@ -61,12 +58,15 @@ const authDataporten = new Authenticator({
authorization: 'https://auth.dataporten.no/oauth/authorization',
userinfo: 'https://auth.dataporten.no/userinfo'
})
authDataporten.jso.setLoader(Popup)
const authORCID = new Authenticator({
providerID: "orcid",
client_id: 'APP-RL4BA8VODEEBZCPN',
redirect_uri: 'http://0.0.0.0:8080/?callback=orcid',
authorization: 'https://orcid.org/oauth/authorize',
userinfo: 'https://auth.dataporten.no/userinfo',
response_type: 'code',
scopes: {
request: ['/authenticate']
}
......@@ -210,8 +210,6 @@ const API = {
"authenticate": function(config) {
return (dispatch, getState) => {
return authDataporten.authenticate().then(([data, token]) => {
// console.log("DATA from Dataporten userinfo endpoint", data)
// console.log("TOKEN", token )
dispatch(actions.authentication.success({user: data.user, token: token.access_token}))
dispatch(API.getORCIDentries())
})
......@@ -227,8 +225,6 @@ const API = {
"orcidReAuth": function() {
return (dispatch, getState) => {
console.error("ORCID REAUTH", this)
let url = 'https://orcid.org/userStatus.json?logUserOut=true'
let config = {"headers": {}}
config.method = "GET"
......@@ -243,13 +239,11 @@ const API = {
throw Error(response.statusText)
})
.then((data) => {
console.log("DATA", data)
dispatch(actions.orcidauth.loggedout(data))
dispatch(API.orcidAuth())
})
.catch((err) => {
console.error("ERROR Logging out of orcid", err)
// console.error("ERROR Logging out of orcid", err)
// dispatch(actions.orcids.completed(err))
})
......@@ -279,7 +273,7 @@ const API = {
return (dispatch, getState) => {
var state = getState()
console.log("STATe IS ", state.authentication.token)
// console.log("STATe IS ", state.authentication.token)
// dispatch(actions.orcids.search())
let url = baseURL + '/orcids/'
let config = {"headers": {}}
......@@ -295,7 +289,7 @@ const API = {
throw Error(response.statusText)
})
.then((data) => {
console.log("DATA Response registering orcid CODE!", data)
// console.log("DATA Response registering orcid CODE!", data)
dispatch(actions.orcidauth.success(data))
dispatch(API.getORCIDentries())
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment