# Authenticate in own rest API with Okta

**URL:** <https://devforum.okta.com/t/authenticate-in-own-rest-api-with-okta/24047>\
**Category:** API\
**Created:** [April 22, 2023, 6:24pm UTC](https://devforum.okta.com/t/authenticate-in-own-rest-api-with-okta/24047 "2023-04-22T18:24:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafael.reis](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rafael.reis](https://devforum.okta.com/u/rafael.reis)\
**Post date:** [April 22, 2023, 6:24pm UTC](https://devforum.okta.com/t/authenticate-in-own-rest-api-with-okta/24047/1 "2023-04-22T18:24:33Z")

</div>

I need to create a .net core API that will validate requests authenticaded by Okta and then release so that the request can access other endpoints.

My project will be depeloped in version 6 or 7 of .net.

In some research I saw we can use these thw approaches

→ Protect your API endpoints:

> **[Protect your API endpoints | Okta Developer](https://developer.okta.com/docs/guides/protect-your-api/aspnetcore3/main/)**
>
> Secure, scalable, and highly available authentication and user management for any app.

→ Validate Access Tokens:

> **[Validate Access Tokens | Okta Developer](https://developer.okta.com/docs/guides/validate-access-tokens/dotnet/main/)**
>
> This guide on tokens shows you how to verify a token's signature, manage key rotation, and how to use a refresh token to get a new access token.

So, from what I understand, we can use the authorize itself on the endpoints with ‘Okta.AspNetCore’ lib, or manually validate the token in our api, is that correct?

If yes, what would be the best way for my project?

---

<div class="post-metadata">

**Author:** ![erik](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@erik](https://devforum.okta.com/u/erik)\
**Post date:** [April 24, 2023, 11:11pm UTC](https://devforum.okta.com/t/authenticate-in-own-rest-api-with-okta/24047/2 "2023-04-24T23:11:49Z")

</div>

Hello,

Typically you would have one application that a user logs into and acquires tokens (authorize/token calls).  
This application would then take the access\_token returned from above and send it to another application which is acting as a resource server. The resource server would grant/deny the request based off of the access\_token provided.

In your scenario it sounds like your application maybe the resource server, or is front of multiple API endpoints (gateway type of behavior?). If so you can check the below sample.

> **[samples-aspnet/resource-server at master · okta/samples-aspnet](https://github.com/okta/samples-aspnet/tree/master/resource-server)**
>
> master/resource-server

If this is not correct and your application will log the user into Okta and receives the tokens from Okta (MVC), I suggest looking at the below sample,

> <https://github.com/okta/samples-aspnet/tree/master/okta-hosted-login>
>
> //github.com/okta/samples-aspnet/tree/master/okta-hosted-login

Thank You,

---

<div class="post-metadata">

**Author:** ![rafael.reis](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rafael.reis](https://devforum.okta.com/u/rafael.reis)\
**Post date:** [April 25, 2023, 5:55pm UTC](https://devforum.okta.com/t/authenticate-in-own-rest-api-with-okta/24047/3 "2023-04-25T17:55:17Z")

</div>

> [@erik](#):
>
> into Okta and receives the tokens from Okta (MVC), I suggest looking at the below sample,

Thaks @erik . I believe this will work for me.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [April 26, 2023, 5:55pm UTC](https://devforum.okta.com/t/authenticate-in-own-rest-api-with-okta/24047/4 "2023-04-26T17:55:56Z")

</div>

Closed on April 26, 2023, 5:55pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
