Can't get any demos working

Hey, I’m new and working on just getting something working. I created a test developer account, but I cannot seem to get any of the auth programs working.

I have downloaded the React and I’m getting an error 400 invalid clientID, but I only get that if I put in my username and password. It is weird.

I downloaded the .net core applications. I ran the self hosted application and I keep getting a cors error. I’ve put in code to get around it " services.AddCors(options => options.AddPolicy(“AllowAll”, p => p.AllowAnyOrigin()));" and " app.UseCors(“AllowAll”);", but I can’t seem to get past that error.

I tried the resource-server thinking it would link to the react, but I cannot get that started. I’m getting an error missing OktaDomain. However, I have it in the appsettings.json next to the client id. I tried different urls reading that sometimes it need the /oath2/default, but that still doesn’t work. “Okta”: {
“ClientId”: “0oafvraokvwgz4yf40h7”,
“OktaDomain”: “https://dev-974365.oktapreview.com/oauth2/default
}

I tried to walk through the quick start, but it isn’t working either: Okta Authentication Quickstart Guides | Okta Developer I ended up deleting the code with the downloaded code.

I’m wondering if this is what I’m missing in the resource server: okta-aspnet/aspnetcore-mvc.md at master · okta/okta-aspnet · GitHub It only has ClientId and Domain. So, I would think it would need to have the secret key too. If I get that running, I can hook it to my react.

Thoughts?

Hey @jeremysloan, sorry about the trouble getting started! We are currently refactoring our documentation to make it clearer.

What is your overall goal? Do you have a React client calling a .NET Core API? If so, you were on the right track. Grab this sample: https://github.com/okta/samples-aspnetcore/tree/master/resource-server

And configure it in ConfigureServices like:

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
    options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
    options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
})
.AddOktaWebApi(new OktaWebApiOptions()
{
    OktaDomain = "https://dev-974365.oktapreview.com"
    ClientId = "0oafvraokvwgz4yf40h7"
});

// ... the rest of ConfigureServices
services.AddMvc();

Then try using Fiddler or Postman to call your API. It should return 401 if no token (or an invalid token) is attached to the request, and 200 if a valid token is attached to the request. (If you want, you can use my free OIDC Debugger tool to easily get an access token for debugging)

Let me know if you get all of the above working and I can help with the React step.

I’ll try that.
In your demo, this is what you currently have:

        services.AddAuthentication(options =>
    {
        options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
        options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
        options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
    })
      .AddOktaWebApi(new OktaWebApiOptions()
      {
          ClientId = Configuration["Okta:ClientId"],
        OktaDomain = Configuration["Okta:OktaDomain"],
      });

It isn’t working on the OktaDomain. I’ll try and hard code it instead of updating the appsettings.json file. I’ll post on here later tonight when I get time.

Thanks for the response.

I see part of what it is:

The json has logging
ClientId = Configuration[Logging:Okta:ClientId"],
OktaDomain = Configuration[“Logging:Okta:OktaDomain”],

I’m getting a 401 now.

You are right, I’m looking to have a react app link to a .net application. I think I have the server going.

I can get the react working, but I’m not currently able to communicate between the two. I’m getting this error on Chrome: Description: The ‘redirect_uri’ parameter must be an absolute URI that is whitelisted in the client app settings.

I tried to add my local host to the whitelist, but that didn’t work.

Is the normal process where the react application auths to Otka. When the token is in the cache of the react app, use that to talk to the .net server?

I’m able to get a bit farther. I’m getting a new error. OAuthError: response type not supported. I see someone else had this issue: Okta-react does not seem to support response_type == code

I tried to change my response type to just token:

authParams: {
responseType: [‘token’],
issuer: config.oidc.issuer,
display: ‘page’,
scopes: config.oidc.scope.split(’ '),
It didn’t make a difference.

There was a bug in the .NET Core API example I linked to, sorry about that. It’s fixed now. Sounds like you got the server working? If you send a request with a valid token, does the server respond with 200?

Can you post the full code you are using to configure okta-react?

Sure. I’m using this: https://github.com/okta/samples-js-react/tree/master/custom-login

I updated the .samples.config:

export default {
oidc: {
clientId: ‘0oagcraovvwgz4yf40h7’,
issuer: ‘https://dev-974465.oktapreview.com/oauth2/default’,
redirectUri: ‘http://localhost:8080/implicit/callback’,
scope: ‘openid profile email’,
},
oidc_old: {
clientId: ‘0oagcraovvwgz4yf40h7’,
issuer: ‘http://127.0.0.1:5000/oauth2/default’,
issuer2: ‘https://dev-974465.oktapreview.com/oauth2/default’,
redirectUri: ‘http://localhost:8080/implicit/callback’,
scope: ‘openid profile email’,
},

resourceServer: {
messagesUrl: ‘http://127.0.0.1:5000/api/messages’,
},
};

Also, I updated the login.jsx responseType as mentioned above.