okta / okta-sdk-dotnet

A .NET SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
Other
159 stars 100 forks source link

No Profile in CreateOpenIdConnectApplication? #457

Closed davekats closed 3 years ago

davekats commented 3 years ago

Current behavior

CreateOpenIdConnectApplication does not contain a property for Profile.

CreateOpenIdConnectApplication appTemplate = new CreateOpenIdConnectApplication {
    Label = label,
    Activate = true,
    ResponseTypes = new List<OAuthResponseType> {
        OAuthResponseType.Code
    },
    GrantTypes = new List<OAuthGrantType> {
        OAuthGrantType.AuthorizationCode
    },
    ApplicationType = OpenIdConnectApplicationType.Service
};

Expected behavior

I'd expect the Profile property to be present so that I can assign key/value pairs, lists, or any JSON friendly data.

CreateOpenIdConnectApplication appTemplate = new CreateOpenIdConnectApplication {
    Label = label,
    Activate = true,
    ResponseTypes = new List<OAuthResponseType> {
        OAuthResponseType.Code
    },
    GrantTypes = new List<OAuthGrantType> {
        OAuthGrantType.AuthorizationCode
    },
    ApplicationType = OpenIdConnectApplicationType.Service,
    Profile = new Dictionary<string, string>() { {"test", "value123"} }
};

If there is some other workaround to this please let me know. I posted this question in the dev forum as well.

Thanks!

Environment

andriizhegurov-okta commented 3 years ago

Hi @davekats, you can assign Profile data after application is created like so:

    var appCreateOptions = new CreateOpenIdConnectApplication
    {
        Label = label,
        Activate = true,
        ResponseTypes = new[] { OAuthResponseType.Code },
        GrantTypes = new[] { OAuthGrantType.AuthorizationCode, OAuthGrantType.ClientCredentials },
        ApplicationType = OpenIdConnectApplicationType.Service,
        RedirectUris = new[] { "https://example.com" },
    };

    var newApp = await oktaClient.Applications.CreateApplicationAsync(appCreateOptions);

    var newProfile = new Resource();
    newProfile["test"] = "value123";
    newApp.Profile = newProfile;
    await oktaClient.Applications.UpdateApplicationAsync(newApp, newApp.Id);
davekats commented 3 years ago

Hi @andriizhegurov-okta, thanks for the workaround. This is actually what I am currently doing, however I'm hoping that there is a way to accomplish this without making a second call to Okta.

andriizhegurov-okta commented 3 years ago

@davekats Yes, you can construct application object manually, fill all the needed properties and then persist it with a single call:

var profile = new Resource();
profile["test"] = "value123";

var app = new OpenIdConnectApplication
{
    Name = "oidc_client",
    Label = label,
    SignOnMode = ApplicationSignOnMode.OpenIdConnect,
    Settings = new OpenIdConnectApplicationSettings
    {
        OAuthClient = new OpenIdConnectApplicationSettingsClient()
        {
            ResponseTypes = new[] { OAuthResponseType.Code },
            RedirectUris = new[] { "https://example.com" },
            GrantTypes = new[] { OAuthGrantType.AuthorizationCode, OAuthGrantType.ClientCredentials },
            ApplicationType = OpenIdConnectApplicationType.Service,
        },
    },
    Profile = profile,
};

var newApp = await oktaClient.Applications.CreateApplicationAsync(application: app, activate: true);
davekats commented 3 years ago

@andriizhegurov-okta That's exactly what I needed. Thank you!