refactored some parts of the hubiC authentication mechanism using javaswift/joss#64