////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

## Configuration

You can configure the following parameters in your application.yml.

.Plugin Configuration Options
[cols="3,1,1,10"]
|===
| Key | Default | Optional | Description

| grails.plugin.springsecurity.oauth2.active
| true
| true
| Whether the plugin is active or not

| grails.plugin.springsecurity.oauth2.registration.askToLinkOrCreateAccountUri
| /oauth2/ask
| true
| The URI is called to ask the user to either create a new account or link an existing

| grails.plugin.springsecurity.oauth2.registration.roleNames
| ['ROLE_USER']
| true
| A list of role names that should be automatically granted to OAuth User. There roles will be created if they do not exists
|===

Here is an example configuration file:

.application.yml
[source,yaml]
----
grails:
  plugin:
    springsecurity:
      oauth2:
        active: true
        registration:
          askToLinkOrCreateAccountUri: /oauth2/ask
          roleNames: ['ROLE_USER']
----

### Initializing

Once you have a User domain class, initialize this plugin by using the init script
[source,bash]
----
./gradlew runCommand "-Pargs=init-oauth2 [DOMAIN-CLASS-PACKAGE] [USER-CLASS-NAME] [OAUTH-ID-CLASS-NAME]"
----

The above command will create the domain class with the provided name and package. For example, the command `./gradlew runCommand "-Pargs=init-oauth2 com.yourapp User OAuthID` will create a domain class `OAuthID.groovy`.

Finally, you also need to add the following domain class relationship mapping to
the `User.groovy` domain class:

.grails-app/domain/com/yourapp/User.groovy
[source,groovy]
----
package com.yourapp

class User {

    // ...

    static hasMany = [oAuthIDs: OAuthID]

}
----
