title: OpenID login in C# desktop application?
body: <p>Im newbie in C#, I have been asked to implement the OpenID login with provided username and password and get the bearer token.</p>
  
  <p>We achieved this in Java code snipped is as below.(don't know how do same in C#)</p>
  
  <pre><code>public AccessTokenResponse getToken() throws IOException, ParseException, Exception {
  
          StringBuilder query = new StringBuilder("");
          ClientCredentialsGrant clientAuth = new ClientCredentialsGrant();
          Map&lt;String, String&gt; parameters = clientAuth.toParameters();
          for (String key : parameters.keySet()) {
              query.append(key).append("=").append(parameters.get(key)).append("&amp;");
          }
  
          ClientID clientID = new ClientID(config.getProperty(ConfigConstants.USERNAME));
  
          Secret secret = new Secret(config.getPassword());
  
          ClientSecretBasic csb = new ClientSecretBasic(clientID, secret);
  
          //logger.info("URL:" + this.getOpenIDMetadata(config.getProperty(ConfigConstants.DOMAIN)).getTokenEndpointURI().toString());
  
          TokenRequest tokenRequest = new TokenRequest(this.getOpenIDMetadata(config.getProperty(ConfigConstants.DOMAIN)).getTokenEndpointURI(), csb, clientAuth);
          HTTPRequest request = tokenRequest.toHTTPRequest();
  
          HTTPResponse httpResponse = request.send();
  
          accessToken = AccessTokenResponse.parse(httpResponse);
  
      return accessToken;
  }
  </code></pre>
  
  <p>We have a server which is an openid provider and this is how get the <strong>OIDCProviderMetadata</strong> </p>
  
  <pre><code>private OIDCProviderMetadata getOpenIDMetadata(String domain) throws Exception {
      if (this.metadata == null) {
          String confURL = this.serverURL+ config.getIDP() + domain + "/authn/.well-known/openid-configuration";
  
          HTTPRequest configRequest = new HTTPRequest(HTTPRequest.Method.GET, new URL(confURL));
          HTTPResponse configResponse = configRequest.send();
          metadata = OIDCProviderMetadata.parse(configResponse.getContent());
      }
      return metadata;
  }
  </code></pre>
  
  <p>Question is how to implement same thing in C#?</p>
  
  <p>I did some research around this, found there is/are official OpendID implementation in C# i.e.
  <a href="https://github.com/IdentityModel/IdentityModel.OidcClient2" rel="nofollow noreferrer">https://github.com/IdentityModel/IdentityModel.OidcClient2</a></p>
  
  <p>but did not find any samples which will help me to implement likewise in Java implementation i have. All examples demonstrate do openid login in browser or mobiles devices i don't want that, I want similar implementation as we have in Java(above).</p>
  
  <p>Any help would be appreciated or code snipped would be more helpful. </p>