Try fetch of token with all possibilities available
@@ -213,39 +213,37 @@ export const determineRequestCredentials = (
)
);
- if (possibleCredentialsForToken.size > 0) {
- const fetchTokenRequestCredentials = possibleCredentialsForToken
- .first()
- .toJS();
+ const fetchThroughPossibleTokenCredentials = async possibleTokenCredentials => {
+ if (possibleTokenCredentials.size > 0) {
+ for (const possibleTokenCred of possibleTokenCredentials) {
+ const fetchTokenRequestCredentials = possibleTokenCred.toJS();
fetchTokenRequestCredentials.scopes = tokenScope;
-
- if (possibleCredentialsForToken.size > 1) {
- console.debug(
- "## more than one possible requestCredential found for this non owned Atom, using first one as the tokenRequester: ",
- fetchTokenRequestCredentials,
- possibleCredentialsForToken
- );
- } else {
- console.debug(
- "## one possible requestCredential found for this non owned Atom, using it as the tokenRequester: ",
- fetchTokenRequestCredentials
- );
- }
-
- return fetchTokenFromAtomAndDispatch(
+ try {
+ const response = await fetchTokenFromAtomAndDispatch(
dispatch,
state,
requestTokenFromAtomUri,
fetchTokenRequestCredentials,
tokenCredential
);
- } /*else {
- //TODO: WHAT DO WE DO IF THERE ARE NO MORE POSSIBILITIES LEFT?
- // return Promise.reject({
- // token: "BLARGH", //TODO: FIX THIS TO WORK WITHOUT MAKING A REQUEST WITH A FAKE-TOKEN
- // obtainedFrom: tokenCredential.toJS(),
- // });
- }*/
+ return response;
+ } catch (error) {
+ console.warn(
+ "Could not obtain token with the given credentials: ",
+ error
+ );
+ }
+ }
+ }
+
+ //FIXME: THIS IS JUST A FAILSAFE TO MARK THE obtainFrom: request option as invalid (since we did not get a token for it yet)
+ return {
+ token: "BLARGH!",
+ obtainedFrom: tokenCredential.toJS(),
+ };
+ };
+
+ return fetchThroughPossibleTokenCredentials(possibleCredentialsForToken);
}
} else {
console.debug(
@@ -367,8 +365,7 @@ export const fetchConnectionsContainerAndDispatch = (
state,
atomUri,
processSelectors.getConnectionContainerRequests(atomUri)(state)
- )
- .then(requestCredentials =>
+ ).then(requestCredentials =>
won
.fetchConnectionUrisWithStateByAtomUri(
atomUtils.getConnectionContainerUri(
@@ -450,15 +447,7 @@ export const fetchConnectionsContainerAndDispatch = (
});
}
})
- )
- .catch(error => {
- // errorParsed 666 marks that we could simply not retrieve the token (yet) there might be a possibility that we can retrieve it another way
- // let us not rule out this request yet
- console.error(
- "could not retrieve token from atom, try again with a different atom....",
- error
);
- });
};
/**
@@ -593,14 +582,6 @@ export const fetchAtomAndDispatch = (
}
})
)
- .catch(error => {
- // errorParsed 666 marks that we could simply not retrieve the token (yet) there might be a possibility that we can retrieve it another way
- // let us not rule out this request yet
- console.error(
- "could not retrieve token from atom, try again with a different atom....",
- error
- );
- })
);
};
