# Okta + MVC web application + Authorization grant flow

**URL:** <https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218>\
**Category:** Questions\
**Created:** [May 4, 2020, 7:00am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218 "2020-05-04T07:00:17Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 4, 2020, 7:00am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/1 "2020-05-04T07:00:17Z")

</div>

Hi Team,

I want to develop MVC web application as a client and Okta as OIDC provider.  
I am new in MVC but i have knowledge of c# and .Net

I have already registered our application in okta server for authorization code .  
Want some sample code in MVC web application that communicate with Okta server for receiving token and userinfo.

Here are some endpoints that need to consume in our client application:  
{“issuer”:“[https://dev-310258.okta.com/oauth2/default",“authorization\_endpoint”:“https://dev-310258.okta.com/oauth2/default/v1/authorize”,“token\_endpoint”:“https://dev-310258.okta.com/oauth2/default/v1/token”,“registration\_endpoint”:“https://dev-310258.okta.com/oauth2/v1/clients”,“jwks\_uri”:“https://dev-310258.okta.com/oauth2/default/v1/keys”,“response\_types\_supported”:[“code”,“token”,“id\_token”,"code](https://dev-310258.okta.com/oauth2/default%22,%22authorization_endpoint%22:%22https://dev-310258.okta.com/oauth2/default/v1/authorize%22,%22token_endpoint%22:%22https://dev-310258.okta.com/oauth2/default/v1/token%22,%22registration_endpoint%22:%22https://dev-310258.okta.com/oauth2/v1/clients%22,%22jwks_uri%22:%22https://dev-310258.okta.com/oauth2/default/v1/keys%22,%22response_types_supported%22:%5B%22code%22,%22token%22,%22id_token%22,%22code) id\_token”,“code token”,“id\_token token”,“code id\_token token”],“response\_modes\_supported”:[“query”,“fragment”,“form\_post”,“okta\_post\_message”],“grant\_types\_supported”:[“authorization\_code”,“implicit”,“refresh\_token”,“password”,“client\_credentials”],“subject\_types\_supported”:[“public”],“scopes\_supported”:[“openid”,“profile”,“email”,“address”,“phone”,“offline\_access”],“token\_endpoint\_auth\_methods\_supported”:[“client\_secret\_basic”,“client\_secret\_post”,“client\_secret\_jwt”,“private\_key\_jwt”,“none”],“claims\_supported”:[“ver”,“jti”,“iss”,“aud”,“iat”,“exp”,“cid”,“uid”,“scp”,“sub”],“code\_challenge\_methods\_supported”:[“S256”],“introspection\_endpoint”:“[https://dev-310258.okta.com/oauth2/default/v1/introspect",“introspection\_endpoint\_auth\_methods\_supported”:[“client\_secret\_basic”,“client\_secret\_post”,“client\_secret\_jwt”,“private\_key\_jwt”,“none”],“revocation\_endpoint”:“https://dev-310258.okta.com/oauth2/default/v1/revoke”,“revocation\_endpoint\_auth\_methods\_supported”:[“client\_secret\_basic”,“client\_secret\_post”,“client\_secret\_jwt”,“private\_key\_jwt”,“none”],“end\_session\_endpoint”:“https://dev-310258.okta.com/oauth2/default/v1/logout”,“request\_parameter\_supported”:true,“request\_object\_signing\_alg\_values\_supported”:[“HS256”,“HS384”,“HS512”,“RS256”,“RS384”,“RS512”,“ES256”,“ES384”,"ES512](https://dev-310258.okta.com/oauth2/default/v1/introspect%22,%22introspection_endpoint_auth_methods_supported%22:%5B%22client_secret_basic%22,%22client_secret_post%22,%22client_secret_jwt%22,%22private_key_jwt%22,%22none%22%5D,%22revocation_endpoint%22:%22https://dev-310258.okta.com/oauth2/default/v1/revoke%22,%22revocation_endpoint_auth_methods_supported%22:%5B%22client_secret_basic%22,%22client_secret_post%22,%22client_secret_jwt%22,%22private_key_jwt%22,%22none%22%5D,%22end_session_endpoint%22:%22https://dev-310258.okta.com/oauth2/default/v1/logout%22,%22request_parameter_supported%22:true,%22request_object_signing_alg_values_supported%22:%5B%22HS256%22,%22HS384%22,%22HS512%22,%22RS256%22,%22RS384%22,%22RS512%22,%22ES256%22,%22ES384%22,%22ES512)”]}

* * *

I want to make client to Implement the Authorization Code Flow with Okta.  
Also want to get user information with their roles in our application.

Case: I am login with my PC using LDAP login and click on my webapplication name as "TestOIDCApp " then my app will detect the username and password and login automatically.

---

<div class="post-metadata">

**Author:** ![Ironhide](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ironhide/32/1799_2.png) [@Ironhide](https://devforum.okta.com/u/Ironhide)\
**Post date:** [May 4, 2020, 3:09pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/2 "2020-05-04T15:09:51Z")

</div>

Okta has a few quickstart guides for .NET implementations but may I recommend using .NET core.  
Older .NET does not support authorization code flows.

Extra info: [https://developer.okta.com/code/dotnet/aspnetcore/](https://developer.okta.com/code/dotnet/aspnetcore/)

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 4, 2020, 3:13pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/3 "2020-05-04T15:13:30Z")

</div>

Thanks For the quick response.

.net Core application is not running , its getting errors.  
like Access token not authorized .

![OIDC-Client](https://global.discourse-cdn.com/oktadev/original/2X/0/008c36a0a8f9821433558753dcf2ec60592b59e1.jpeg)

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 5, 2020, 1:49pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/4 "2020-05-05T13:49:59Z")

</div>

Is anybody there to help me for resolving this .

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 6, 2020, 8:49am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/5 "2020-05-06T08:49:17Z")

</div>

Hi Sander,

Please help me to run existing application bug free.

Also tell me about scopes? what is this and how to manage in our existing application?

---

<div class="post-metadata">

**Author:** ![Ironhide](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ironhide/32/1799_2.png) [@Ironhide](https://devforum.okta.com/u/Ironhide)\
**Post date:** [May 6, 2020, 9:35am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/6 "2020-05-06T09:35:26Z")

</div>

That is my example and I am using custom scopes.  
openid profile  
try those 2.

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 6, 2020, 10:00am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/7 "2020-05-06T10:00:31Z")

</div>

Thanks for the help dear.  
After change the scope as per above , main page redirect to Okta login page.  
Once login on that page , redirect to the below url:

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/c/cedaa4abaaa95410f117e7b42c943fbeda402a8d.png)

How can we use this code to get the ID token after Authorization code received.  
What should be the next step, after receive the token i want to redirect to the main page .

Your support is very much valuable to me a lot.

---

<div class="post-metadata">

**Author:** ![Ironhide](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ironhide/32/1799_2.png) [@Ironhide](https://devforum.okta.com/u/Ironhide)\
**Post date:** [May 6, 2020, 11:03am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/8 "2020-05-06T11:03:51Z")

</div>

Have a look at the callback url (placed in homecontroller). There should be something that calls getToken(code).

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 6, 2020, 2:33pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/9 "2020-05-06T14:33:58Z")

</div>

You are right dear, i have received the access token after exchange the authorization code,  
but after received the token need to display user profile in some sample page.

Only access token is received but how to get "“id\_token” and "“refresh\_token” as per same as below sample:

{  
“access\_token”: “NWE4Nzg2ZDEtNzQyMS00ZDViLThjMjctMGQwNjlmZjU5MWNkBGjFElT7CWzl0d…”,  
“expires\_in”: 3600,  
“id\_token”: “eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkpSY080bnhzNWpnYzhZZE43STJoTE80V…”,  
“token\_type”: “Bearer”,  
“refresh\_token”: “897987AGBEtNzQyMS00ZDViLThjMjctMGQwNjlmZjU5MWNkBGjFElT7CWzl0d…”  
}

How and where to use /userinfo endpoint in existing code?  
Also help me about the below code , in our existing client code want to add /userinfo endpoint.

Please share the source code for this.

```auto

```

---

<div class="post-metadata">

**Author:** ![laura.rodriguez](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/laura.rodriguez/32/611_2.png) [@laura.rodriguez](https://devforum.okta.com/u/laura.rodriguez)\
**Post date:** [May 8, 2020, 4:59pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/10 "2020-05-08T16:59:27Z")

</div>

Hi @bhavyakhanna,

We have several examples on GH, check out the following links:

- [https://github.com/okta/samples-aspnetcore](https://github.com/okta/samples-aspnetcore)
- [https://github.com/okta/samples-aspnet](https://github.com/okta/samples-aspnet)
- [https://github.com/okta/samples-aspnet-webforms](https://github.com/okta/samples-aspnet-webforms)

Also, I recommend to check out our guides where you can find step-by-step instructions to get started: [https://developer.okta.com/docs/guides/sign-into-web-app/aspnet/before-you-begin/](https://developer.okta.com/docs/guides/sign-into-web-app/aspnet/before-you-begin/).

I hope this helps!

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 11, 2020, 6:54am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/11 "2020-05-11T06:54:02Z")

</div>

Hi,

I have checked out the below guide earlier , but i am getting confused.  
NO CallBack URL endpoint is mentioned in the [ASP.Net](http://ASP.Net) web form example.

As such no single article that can describe a to z ,i mean Authorization grant flow using OIDC protocol to authenticate the user without opening the login page in .NET MVC Web application.

Just need to authenticate my [ASP.net](http://ASP.net) web application with OKta server via Back channel authentication and get user profile from the server.

Please share the step by step guide code according to my problem.

Thanks !!!

---

<div class="post-metadata">

**Author:** ![laura.rodriguez](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/laura.rodriguez/32/611_2.png) [@laura.rodriguez](https://devforum.okta.com/u/laura.rodriguez)\
**Post date:** [May 11, 2020, 2:55pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/12 "2020-05-11T14:55:49Z")

</div>

Hi,

Sorry, I missed the part you are using LDAP for login. I haven’t tried this by myself before, but let me share some resources that might help you.

There’s a guide to implement the Authorization grant flow, you can check it out here: [https://developer.okta.com/docs/guides/implement-auth-code/overview/](https://developer.okta.com/docs/guides/implement-auth-code/overview/).

Regarding using OIDC and skipping the Okta login page, you can use OWIN which should make your life easier. It has an `AuthenticationMode` property that you can set to `AuthenticationMode.Passive,` so it wouldn’t try to authenticate to Okta immediately.

Anyways, I suggest you contact [support@okta.com](mailto:support@okta.com) (or open a support ticket via [https://developer.okta.com/contact/](https://developer.okta.com/contact/)). They can help you with your application to troubleshoot this issue.

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 12, 2020, 6:57am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/13 "2020-05-12T06:57:45Z")

</div>

Hi,  
Yes i am using LDAP for login, but no sample given in okta solution guide.  
In some example Redirect URI definition is not mentioned and some example some endpoints are missing.  
Please help me to share full fledged example code with OWIN.

Regards,  
Bhavya khanna

---

<div class="post-metadata">

**Author:** ![Ironhide](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ironhide/32/1799_2.png) [@Ironhide](https://devforum.okta.com/u/Ironhide)\
**Post date:** [May 12, 2020, 8:27am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/14 "2020-05-12T08:27:23Z")

</div>

> [@bhavyakhanna](#):
>
> You are right dear, i have received the access token after exchange the authorization code,  
> but after received the token need to display user profile in some sample page.
> 
> Only access token is received but how to get "“id\_token” and "“refresh\_token” as per same as below sample:
> 
> {  
> “access\_token”: “NWE4Nzg2ZDEtNzQyMS00ZDViLThjMjctMGQwNjlmZjU5MWNkBGjFElT7CWzl0d…”,  
> “expires\_in”: 3600,  
> “id\_token”: “eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkpSY080bnhzNWpnYzhZZE43STJoTE80V…”,  
> “token\_type”: “Bearer”,  
> “refresh\_token”: “897987AGBEtNzQyMS00ZDViLThjMjctMGQwNjlmZjU5MWNkBGjFElT7CWzl0d…”  
> }
> 
> How and where to use /userinfo endpoint in existing code?  
> Also help me about the below code , in our existing client code want to add /userinfo endpoint.
> 
> Please share the source code for this.

If you are using the tokenservice in my example, you also have a class called OktaToken, this is where I map the json you just posted. If you add 2 more properties for refresh\_token and id\_token then you will also have it in an object. Originally I only return the access\_token (in GetToken method, there you see it return token.access\_token or something like that). Instead of doing that you can also just return the entire OktaToken object and take out whatever you need in your method.

If you got above json, you basically authenticated the user…

The easiest option is to use implicit flow for [ASP.net](http://ASP.net) (not authorization code), less secure but that is only available for the older framework

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 12, 2020, 8:40am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/15 "2020-05-12T08:40:30Z")

</div>

> [@Ironhide](#):
>
> The easiest option is to use implicit flow for [ASP.net](http://ASP.net) (not authorization code), less secure but that is only available for the older framework

I understand the above, but what is the best way to Authenticate with okta via LDAP login.

Scenario: User login via LDAp in the system , after loggedin hit the application URL and then authenticate the user with okta at backend with OIDC and show the main application infront of user.

Thanks !!!

---

<div class="post-metadata">

**Author:** ![Ironhide](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ironhide/32/1799_2.png) [@Ironhide](https://devforum.okta.com/u/Ironhide)\
**Post date:** [May 12, 2020, 8:53am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/16 "2020-05-12T08:53:26Z")

</div>

Okta supports delegathed authentication for LDAP. If you set that up a user can login using his LDAP credentials from the okta login screen and he will be authenticated. No fancy setup needed, the flow works exactly the same as a normal login but behind the screens okta will check the credentials with LDAP.

[https://help.okta.com/en/prod/Content/Topics/Security/Security\_Authentication.htm](https://help.okta.com/en/prod/Content/Topics/Security/Security_Authentication.htm)

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 12, 2020, 10:17am UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/17 "2020-05-12T10:17:16Z")

</div>

Ok, giving information is very useful.

But forgot all the things, first of all just focus on our “client” application.

1. List item

Only need to display user information which is getting in “access token” after authorization.

1. List item

As per below your comment"  
“The cool thing is that you can start using claim based protection. This also ensures you have SSO. Once you have an Okta session, Okta will keep sending you access tokens so the user is not prompted with a login screen everytime.”

I also want that user is not prompted okta login page again and again.

Just help me on that part only.!!

---

<div class="post-metadata">

**Author:** ![bhavyakhanna](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bhavyakhanna](https://devforum.okta.com/u/bhavyakhanna)\
**Post date:** [May 12, 2020, 12:32pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/18 "2020-05-12T12:32:53Z")

</div>

@Ironhide, please share the updated code that display the userinfo into samplepage.

do changes in same “client” code.

Please share today, because its urgent for me.  
Thanks!!!

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 24, 2024, 7:47pm UTC](https://devforum.okta.com/t/okta-mvc-web-application-authorization-grant-flow/9218/19 "2024-01-24T19:47:43Z")

</div>

Closed on January 24, 2024, 7:47pm UTC


