# Build Server Side Authentication in Grails with OAuth 2.0 and Okta

**URL:** <https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856>\
**Category:** Developer Blog Comments\
**Created:** [April 19, 2018, 5:07pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856 "2018-04-19T17:07:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [April 19, 2018, 5:07pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/1 "2018-04-19T17:07:24Z")

</div>

[Build Server Side Authentication in Grails with OAuth 2.0 and Okta](https://developer.okta.com/blog/2018/04/19/okta-with-grails)

This is a quick tutorial demonstrating how to add authentication to a Grails application with Okta.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 26, 2018, 12:06pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/2 "2018-11-26T12:06:24Z")

</div>

**rupak dutta**

Hi andrew, after performing part 1, when i try to login with this link [http://localhost:8080/home/index](http://localhost:8080/home/index). its always giving this error “Sorry, we were not able to find a user with that username and password.” . i am seeing an error occurred in terminal as : "grails.plugin.springsecurity.oauth2.exception.OAuth2Exception: No provider ‘okta’ "  
any body else got this error?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 27, 2018, 12:56am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/3 "2018-11-27T00:56:48Z")

</div>

**Matt Raible**

What configuration settings do you have in your `application.yml`? They should resemble the following (with CLIENT\_ID and CLIENT\_SECRET populated from your app and dev-737523 replaced with your Okta org):

```
grails: ### other grails config settings ### plugin: springsecurity: oauth2: active: true registration: roleNames: [‘ROLE_USER’] providers: okta: api_key: ‘CLIENT_ID’ api_secret: ‘CLIENT_SECRET’ userInfoUrl: ‘https://dev-737523.oktapreview.com/oauth2/default/v1/userinfo’ authorizeUrl: ‘https://dev-737523.oktapreview.com/oauth2/default/v1/authorize’ tokenUrl: ‘https://dev-737523.oktapreview.com/oauth2/default/v1/token’ scopes: ‘email profile openid’
```

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 27, 2018, 7:13am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/4 "2018-11-27T07:13:37Z")

</div>

**rupak dutta**

Hi Matt,  
 thanks for your reply. i am sharing configurations of application.yml.

[https://uploads.disquscdn.c…](https://uploads.disquscdn.com/images/c6153fe765107260e288f8c166834b6b17ec28d634b7ee429fa7e0a8155e9840.jpg "https://uploads.disquscdn.com/images/c6153fe765107260e288f8c166834b6b17ec28d634b7ee429fa7e0a8155e9840.jpg")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 27, 2018, 7:24am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/5 "2018-11-27T07:24:37Z")

</div>

**rupak dutta**

i have modified appication.yml by removing ‘-admin’ string from userInfoUrl,authorizeUrl,tokenUrl. but still getting same error “no provider. okta”.  
my configurations :

plugin:  
 springsecurity:  
 oauth2:  
 active: true  
 registration:  
 roleNames: [‘ROLE\_USER’]  
 providers:  
 okta:  
 api\_key: ‘0oaht93r35EmQ5bN20h7’  
 api\_secret: ‘cyKrCFmK-\_pVZBhYq2HHLx1FERkdGcAAfN\_pBhxO’  
 userInfoUrl: '[https://dev-764990.oktaprev…](https://dev-764990.oktapreview.com/oauth2/default/v1/userinfo' "https://dev-764990.oktapreview.com/oauth2/default/v1/userinfo'")  
 authorizeUrl: '[https://dev-764990.oktaprev…](https://dev-764990.oktapreview.com/oauth2/default/v1/authorize' "https://dev-764990.oktapreview.com/oauth2/default/v1/authorize'")  
 tokenUrl: '[https://dev-764990.oktaprev…](https://dev-764990.oktapreview.com/oauth2/default/v1/token' "https://dev-764990.oktapreview.com/oauth2/default/v1/token'")  
 scopes: ‘email profile openid’

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 27, 2018, 1:12pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/6 "2018-11-27T13:12:33Z")

</div>

**Matt Raible**

It looks like you have the plugin defined under the “gorm” key when it should be defined under the “grails” key. Outdent the plugin block 8 spaces and it should solve your issue.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 12, 2018, 7:57am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/7 "2018-12-12T07:57:47Z")

</div>

**rupak dutta**

Hi thanks for the previous reply, those were really helpful. i have another issue.  
1. when ever i integrate my application with okta the default /ask page comes for first time login and i need to create an user in order to proceed. but my business logic states that after login the control should invoke my controller bypassing the /ask form page. How to bypass the /ask page?

2. even if i create a new user from /ask page, i could not find the user in my okta account. why?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 12, 2018, 4:27pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/8 "2018-12-12T16:27:22Z")

</div>

**Matt Raible**

Where does your `/ask` page come from? There’s nothing in this tutorial that references a URL like that, so I’m not sure how your question is related to this blog post.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 18, 2019, 6:14pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/9 "2019-08-18T18:14:02Z")

</div>

**Flarespots**

Hi!  
Is there a way of using multiple Okta providers inside the Grails configuration? Or even better … is there a way of adding multiple providers “dynamically” ?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 18, 2019, 6:17pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/10 "2019-08-18T18:17:10Z")

</div>

**Matt Raible**

Can you explain your use case a bit and why you have a need for this?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 18, 2019, 6:49pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/11 "2019-08-18T18:49:05Z")

</div>

**Flarespots**

Hi Matt!  
Thanks for your quick response.

Sure! This is the scenario:

We are selling a service through a Grails app for a client that uses Okta. However, there is a possibility to sell that service to other potential clients that also uses it…

We don’t want to create a different instance of that app for each client, instead, we’d like to keep a single instance with multiple users or licenses.

Can you please point me to the right direction on how to do this ?

Thanks and regards!

–  
Ricardo V.  
Flarespots

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 19, 2019, 12:54am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/12 "2019-08-19T00:54:17Z")

</div>

**Matt Raible**

Since Grails is built on Spring Boot, you can use Spring Boot’s [externalized configuration](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html "https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html") feature to set Okta properties outside your app. We recommend using environment variables, Spring Cloud Config (if you’re using microservices), or one of Spring Boot’s other mechanisms. You should be able to switch Okta tenants using this feature, without modifying the artifact.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 19, 2019, 4:46pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/13 "2019-08-19T16:46:46Z")

</div>

**Flarespots**

Great!   
I’m going to check on that.  
Thank you very much for your advice!

–  
Ricardo V.  
Flarespots

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 27, 2019, 8:47pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/14 "2019-08-27T20:47:31Z")

</div>

**Ricardo**

Hi Andrew! This is a great article, thanks for sharing it!   
Is it possible to enable OKTA into a Grails project without losing the capacity to login through a Spring Security Core form or through REST ?

Thank you!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 31, 2019, 6:02pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/15 "2019-08-31T18:02:35Z")

</div>

**Matt Raible**

Spring Security 5.1+ has support for multiple authentication mechanisms, do it depends on what version of Grails you’re using.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 17, 2019, 9:42am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/16 "2019-12-17T09:42:12Z")

</div>

**tr tr**

I also had to add to app settings in Okta   
[https://uploads.disquscdn.c…](https://uploads.disquscdn.com/images/bb3ac4fe319ae95abd4b2417aa87a1e3e01911f83a632cc81c64a86c49cc76ab.png "https://uploads.disquscdn.com/images/bb3ac4fe319ae95abd4b2417aa87a1e3e01911f83a632cc81c64a86c49cc76ab.png")

In the guide,   
From your Okta admin panel, click on Applications in the top menu and then click “Add Application”  
of   
**Create Your Okta Application**

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [April 29, 2020, 6:34pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/17 "2020-04-29T18:34:46Z")

</div>

**Al**

Is there any reason for the restrictions in grails version for the plugin except you wrote it on that version? I tried to adapt this for an existing application, running on grails 3.0.8 by modifying your plugin so this would be allowed. It seems I am first redirected to success then spring wiring fails or something like that and I am redirected to the ask login page. Which will always redirect me again to itself in the end if I try to login. Any tips how this could be troubleshooted? I am not exactly a spring expert. Somehow userdata, which I can see in trace, seems not to be used at all, it seems to me there is never a user object created with the data I get from okta.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [May 23, 2020, 4:18pm UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/18 "2020-05-23T16:18:02Z")

</div>

**Matt Raible**

You said you modified the Grails plugin used in this post. Is it possible for you to share your modifications? Ideally, they would be in the form of a pull request, but we’ll take anything you’re willing to share.

We’d like to help make the latest version of Grails work with Okta!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 10, 2021, 3:31am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/19 "2021-06-10T03:31:52Z")

</div>

**John Ruggentaler**

I cloned the repository for this project and updated the configuration and updated the project to Grails 3.3.11 but when I browse to a secured controller I get the following error.  
`400Bad RequestYour request resulted in an error. The ‘redirect_uri’ parameter must be a Login redirect URI in the client app settings: https://<domainname>.oktapreview.com/admin/app/oidc_client/instance/<api_key>#tab-general`

Any idea what might be wrong?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 10, 2021, 4:51am UTC](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856/20 "2021-06-10T04:51:19Z")

</div>

**Matt Raible**

You can see the parameter you’re passing in by inspecting the URL in your browser when you see this error. Add it to your Okta app and you should be in business.

[Next page](https://devforum.okta.com/t/build-server-side-authentication-in-grails-with-oauth-2-0-and-okta/16856.md?page=2)
