AccessToken findToken()

in plugin-rest/spring-security-rest/src/main/groovy/grails/plugin/springsecurity/rest/token/bearer/BearerTokenReader.groovy [38:58]


    AccessToken findToken(HttpServletRequest request) {
        log.debug "Looking for bearer token in Authorization header, query string or Form-Encoded body parameter"
        String tokenValue = null
        String header = request.getHeader('Authorization')

        if (header?.startsWith('Bearer') && header.length()>=8) {
            log.debug "Found bearer token in Authorization header"
            tokenValue = header.substring(7)
        } else if (isFormEncoded(request) && !request.get) {
            log.debug "Found bearer token in request body"
            tokenValue = request.parameterMap['access_token']?.first()
        } else if (request.queryString?.contains('access_token')) {
            log.debug "Found bearer token in query string"
            tokenValue = request.getParameter('access_token')
        } else {
            log.debug "No token found"
        }

        log.debug "Token: ${tokenValue}"
        return tokenValue ? new AccessToken(tokenValue) : null
    }