0

Windows フォーム アプリケーションからユーザーを作成しようとしています。

コンソールアプリでなんとかできましたが、適切なWindowsアプリでやりたいです。:)

認証を正しく行うには、AssertionFlowClient がどのように機能しているかを理解しようとしましたが、うまくいきません。

重要なコードは次のとおりです。

private void CreateUserBtn_Click(object sender, EventArgs e)
    {
        var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, new X509Certificate2(@"C:\key.p12", "notasecret", X509KeyStorageFlags.Exportable))
        {
            ServiceAccountId = "somemail@developer.gserviceaccount.com",
            Scope = DirectoryService.Scopes.AdminDirectoryUser.GetStringValue(),
            ServiceAccountUser = "myadress@mydomain.mygbiz.com",
        };

        var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);

        DirectoryService m_serviceUser = new DirectoryService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
        });
        User newuserbody = new User();
        UserName newusername = new UserName();
        newuserbody.PrimaryEmail = UserNameTextBox.Text + "@" + DomainTextBox.Text;
        newusername.GivenName = GivenNameTextBox.Text;
        newusername.FamilyName = FamilyNameTextBox.Text;
        newuserbody.Name = newusername;
        newuserbody.Password = PasswordTextBox.Text;

        m_serviceUser.Users.Insert(newuserbody).Execute();
    }

エラーメッセージは次のとおりです。

タイプ 'DotNetOpenAuth.Messaging.ProtocolException' の未処理の例外が Google.Apis.dll で発生しました

追加情報: ダイレクト メッセージの送信中または応答の取得中にエラーが発生しました。

編集:somデバッグ出力を再度追加:

CreateUserWinForm.vshost.exe Information: 0 : DotNetOpenAuth, Version=4.0.0.11165, Culture=neutral, PublicKeyToken=2780ccd10d57b246 (official)

CreateUserWinForm.vshost.exe Information: 0 : Preparing to send AssertionFlowMessage (2.0) message.

CreateUserWinForm.vshost.exe Information: 0 : Sending AssertionFlowMessage request.

CreateUserWinForm.vshost.exe Information: 0 : HTTP POST https://accounts.google.com/o/oauth2/token

'CreateUserWinForm.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.resources\v4.0_4.0.0.0_sv_b77a5c561934e089\System.resources.dll'

A first chance exception of type 'DotNetOpenAuth.Messaging.ProtocolException' occurred in DotNetOpenAuth.dll

Additional information: Error occurred while sending a direct message or getting the response.

A first chance exception of type 'DotNetOpenAuth.Messaging.ProtocolException' occurred in Microsoft.Threading.Tasks.dll

Additional information: Error occurred while sending a direct message or getting the response.

A first chance exception of type 'System.AggregateException' occurred in mscorlib.dll

A first chance exception of type 'DotNetOpenAuth.Messaging.ProtocolException' occurred in Google.Apis.dll

Additional information: Error occurred while sending a direct message or getting the response.

An unhandled exception of type 'DotNetOpenAuth.Messaging.ProtocolException' occurred in Google.Apis.dll

Additional information: Error occurred while sending a direct message or getting the response.

The program '[7820] CreateUserWinForm.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
4

1 に答える 1