Question
· Feb 17, 2022

Creating an OAuth2 server from code

LS,

Is there a samples on how to create the OAuth2 server from code? Now trying:
 

set oauth2server = ##class(OAuth2.Server.Configuration).%New()
set oauth2server.Key = "singleton"
set oauth2server.IssuerEndpoint = "https://localhost:52773/oauth2"
set oauth2server.Description = "MedMij Authorization Server"
set oauth2server.AccessTokenInterval = 900
set oauth2server.AuthorizationCodeInterval = 900
set oauth2server.RefreshTokenInterval = 3600
set oauth2server.SessionInterval = 3600
set oauth2server.ClientSecretInterval = 0
set oauth2server.SupportedScopes = "ikp-scope"
set oauth2server.DefaultScope = "ikp-scope"
set oauth2server.AllowUnsupportedScope = 1
set oauth2server.SupportedGrantTypes = "A"
set oauth2server.SSLConfiguration = "MedMij Oauth2Server"
set sc = oauth2server.%Save()
Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2021.1 (Build 215U) Wed Jun 9 2021 13:47:40 UTC
Discussion (2)2
Log in or sign up to continue

As Alexander said, the Creating the Server Configuration Items Programmatically link should have the information you need. Note, in particular, the types of the properties. Looking at what you have here, the IssuerEndpoint and SupportedScopes properties are of the wrong type: IssuerEndpoint needs to be an OAuth2.Endpoint object and SupportedScopes is an array of strings so should be set withdo oauth2server.SupportedScopes.SetAt(<scope description>,"ikp-scope")