I have an ios app which communicates with a REST API developed on Grails. In order to secure the REST API, I decided to use oAuth 2.0 'Resource Owner Password' flow. For the grails app to act as an oAuth 2.0 provider I am using the following http://grails.org/plugin/spring-security-oauth2-provider For Client with id as 'client' ,secret as '1234' and User with username as 'user' and password as 'password',the request for token is as follows
POST /oauth2-test/oauth/token HTTP/1.1
Host: 192.168.1.113:8080
Authorization: Basic Y2xpZW50OjEyMzQ=
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
grant_type=password&scope=read&username=user&password=password
The response received is
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
My config.groovy edits for Spring Security and oAuth 2.0 provider plugin looks like this
// Added by the Spring Security Core plugin:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'test.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'test.UserRole'
grails.plugin.springsecurity.authority.className = 'test.Role'
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/': ['permitAll'],
'/index': ['permitAll'],
'/index.gsp': ['permitAll'],
'/assets/**': ['permitAll'],
'/**/js/**': ['permitAll'],
'/**/css/**': ['permitAll'],
'/**/images/**': ['permitAll'],
'/**/favicon.ico': ['permitAll'],
'/oauth/authorize.dispatch': ["isFullyAuthenticated() and (request.getMethod().equals('GET') or request.getMethod().equals('POST'))"],
'/oauth/token.dispatch' : ["isFullyAuthenticated() and request.getMethod().equals('POST')"]
]
// Added by the Spring Security OAuth2 Provider plugin:
grails.plugin.springsecurity.oauthProvider.clientLookup.className = 'test.Client'
grails.plugin.springsecurity.oauthProvider.authorizationCodeLookup.className = 'test.AuthorizationCode'
grails.plugin.springsecurity.oauthProvider.accessTokenLookup.className = 'test.AccessToken'
grails.plugin.springsecurity.oauthProvider.refreshTokenLookup.className = 'test.RefreshToken'
grails.plugin.springsecurity.providerNames = [
'clientCredentialsAuthenticationProvider',
'daoAuthenticationProvider',
'anonymousAuthenticationProvider',
'rememberMeAuthenticationProvider'
]
grails.exceptionresolver.params.exclude = ['password', 'client_secret']
grails.plugin.springsecurity.filterChain.chainMap = [
'/oauth/token': 'JOINED_FILTERS,-oauth2ProviderFilter,-securityContextPersistenceFilter,-logoutFilter,-rememberMeAuthenticationFilter',
'/api/**': 'JOINED_FILTERS,-securityContextPersistenceFilter,-logoutFilter,-rememberMeAuthenticationFilter',
'/**': 'JOINED_FILTERS,-statelessSecurityContextPersistenceFilter,-oauth2ProviderFilter,-clientCredentialsTokenEndpointFilter'
]
- What am i doing wrong? I understand oAuth 2.0 is primarily for authorization and not authentication. So do I have to explicitly add a filter for authentication?I started with Grails without any experience on Springs and any help is appreciated as to how to do it?
- Does grant_type 'password' require client authentication? For grant
type 'password' should user authentication not suffice?Even if it needs to authenticate the client it would use Basic Authentication according to my understanding. So do I need to explicitly add a basic authentication filter?