Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create new Application with KeyCredential #46

Closed
adriankostrubiak-tomtom opened this issue Dec 6, 2021 · 2 comments · Fixed by #51
Closed

Unable to create new Application with KeyCredential #46

adriankostrubiak-tomtom opened this issue Dec 6, 2021 · 2 comments · Fixed by #51
Assignees
Labels
bug Something isn't working fixed

Comments

@adriankostrubiak-tomtom
Copy link

I am unable to create a new Application with included KeyCredential due to seeming json serialization issues.

When I dig in with the debugger, I see the returned response from the API:

Expected property 'type_escaped' is not present on resource of type 'KeyCredential'

The following is a sample snippet which I used to repro this issue. Some values will have to be adjusted, of course :)

package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	a "github.com/microsoft/kiota/authentication/go/azure"
	msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	"github.com/microsoftgraph/msgraph-sdk-go/applications"
	"github.com/microsoftgraph/msgraph-sdk-go/models/microsoft/graph"
	"io/ioutil"
	"log"
)

func main() {
	_, pemBytes := getPEMBytes()
	cert, key, _ := azidentity.ParseCertificates(pemBytes, nil)
	cred, _ := azidentity.NewClientCertificateCredential("my-tenant-id", "my-client-id",
		cert, key, &azidentity.ClientCertificateCredentialOptions{})

	auth, _ := a.NewAzureIdentityAuthenticationProviderWithScopes(cred, []string{".default"})
	adapter, _ := msgraphsdk.NewGraphRequestAdapter(auth)
	client := msgraphsdk.NewGraphServiceClient(adapter)

	managedApp := graph.NewApplication()
	n := "my-test-application"
	managedApp.SetDisplayName(&n)

	managedAppKeyCred := graph.NewKeyCredential()
	keyBytes, _ := ioutil.ReadFile("new-app-credential.crt")
	managedAppKeyCred.SetKey(keyBytes)
	managedAppKeyCred.SetDisplayName(&n)
	t := "AsymmetricX509Cert"
	managedAppKeyCred.SetType_escaped(&t)
	u := "Verify"
	managedAppKeyCred.SetUsage(&u)
	managedApp.SetKeyCredentials([]graph.KeyCredential{*managedAppKeyCred})

	options := applications.ApplicationsRequestBuilderPostOptions{
		Body: managedApp,
	}

	result, err := client.Applications().Post(&options)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("yay: %s", *result.GetAppId()) // note that in current state, this panics since the API returns an error but the SDK does not handle it (I'm aware this is a known issue)
}

I have just re-run go get -u and retested and this error persists.

go get -u                                        
go: downloading golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71
go get: upgraded github.com/microsoft/kiota/abstractions/go v0.0.0-20211201125630-3501743a5dc5 => v0.0.0-20211203190524-b3aa0a7d4445
go get: upgraded github.com/microsoft/kiota/http/go/nethttp v0.0.0-20211130101617-a4871ba0f35f => v0.0.0-20211203190524-b3aa0a7d4445
go get: upgraded github.com/microsoft/kiota/serialization/go/json v0.0.0-20211112084539-17ac73ffdc7c => v0.0.0-20211203190524-b3aa0a7d4445
go get: upgraded github.com/microsoftgraph/msgraph-sdk-go-core v0.0.4 => v0.0.5
go get: upgraded github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 => v0.0.0-20210911075715-681adbf594b8
go get: upgraded golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 => v0.0.0-20211202192323-5770296d904e
go get: upgraded golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9 => v0.0.0-20211205041911-012df41ee64c
go get: upgraded golang.org/x/sys v0.0.0-20210423082822-04245dca01da => v0.0.0-20211205182925-97ca703d548d
@baywet
Copy link
Member

baywet commented Dec 7, 2021

Hi @adriankostrubiak-tomtom

Thanks for reaching out and for trying the SDK.

This is caused by a bug in the generator. I've authored microsoft/kiota#926 to address this.
I've also kicked new generation PRs to reflect the changes in the SDK #51.

Once the pull requests get merged, this issue will be closed, then just run go get -u at the root of your project to get the update.

@baywet baywet added the fixed label Dec 7, 2021
@baywet baywet closed this as completed in #51 Dec 8, 2021
@baywet
Copy link
Member

baywet commented Dec 8, 2021

FYI the pull request has been merged and the tag has been created. Updating your dependencies should fix the issue on your side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants