Giter Club home page Giter Club logo

oauth2_dotnetcore_mvc5_sampleapp's Introduction

Rate your SampleYesNo

OAuth2_DotnetCore_MVC5_SampleApp

DotNet Core MVC5 Sample app using .NET Standard SDK

The Intuit Developer team has written this OAuth 2.0 Sample App in .Net Core(C#) MVC5 to provide working examples of OAuth 2.0 concepts, and how to integrate with Intuit endpoints. It uses the Owin Context to save the user cookies for the session. More details can be read here and here

Getting Started

Before beginning, it may be helpful to have a basic understanding of OAuth 2.0 flow. There are plenty of tutorials and guides to get started with OAuth 2.0. Check out the docs on https://developer.intuit.com/

PreRequisites

  1. Visual Studio 2019 or above
  2. Microsoft.Net.Compilers 2.10.0
  3. .Net Core 3.1

Setup

Clone this repository/Download the sample app.

Configuring your app

All configuration for this app is located in appsettings.json. Locate and open this file.

We will need to update the below items items:

  1. ClientId
  2. ClientSecret
  3. RedirectURL
  4. Environment
  5. DBConnectionString (Optional)
  6. QBOBaseURL

Client Credentials

Once you have created an app on Intuit's Developer Portal, you can find your credentials (Client ID and Client Secret) under the "Keys" tab. You will also find a section to enter your Redirect URL here.

Redirect URI

You'll have to set a Redirect URI in both 'web.config' and the Developer Portal ("Keys" section). With this app, the typical value would be https://localhost:47331/connect/index, unless you host this sample app in a different way (if you were testing HTTPS, for example or changing the port).

Scopes

This sample app requires Accounting scope, please choose this if creating a new app.

DBConnectionString

This sample app uses a SQLite database to store the tokens(AccessToken and RefreshToken) used for doing our API calls and also update the token with new tokens when the token expires. This database is created for you the first time your run the sample.

Run your app!

After setting up both Developer Portal and your appsettings.json, run the sample app.

Connect To QuickBooks

This flow goes through authorization flow where QBO user logs in and authorizes your app. At the end of this process, the app will end up with tokens and if you are a first time user it will create new tokens in the database and if you a recurring user and if your tokens are expired then it will update the database.

QBO API request

Access tokens from Connect to QuickBooks flow are used to make a Customer and Invoice request which allows to create a customer and invoice in your company. If any tokens are expired, then it refresh those tokens based on the refresh token.

oauth2_dotnetcore_mvc5_sampleapp's People

Contributors

cbehrends avatar dependabot[bot] avatar johncampionjr avatar nimisha84 avatar rkasaraneni20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

oauth2_dotnetcore_mvc5_sampleapp's Issues

Sample does not appear to work

I added all of the credentials that it asked for. It does authenticate and get a token, but then it fails with "Forbidden" when any action is performed.

Issues with QBO page methods

Hoping this helps someone who ran into these same issues as I was unable to find any help googling for several days.

This sample app did not work all the way for me. The Connect method worked find but the QBO methods never worked (Create Customer / Create Invoice).

1.)
Initially I realized I had to manually enter the RealmId, AccessToken and RefreshToken into the SQLite database as it was not getting populated during the Connect method. I think this may be as expected though?

2.)
Then when clicking the Create Customer button on the QBO.cshtml page, I encountered a null reference error at this line in the related method in the Services file -
if (token.AccessToken != null && token.RealmId != null).

This seemed to be caused by this preceding line not returning anything into the token due to the _auth2Keys.RealmId value being null-
var token = await _tokens.Token.FirstOrDefaultAsync(t => t.RealmId == _auth2Keys.RealmId);

To fix this I added a new line for RealmId to appSettings.json in the OAuth2Keys section and populated it with the QB company realmid value needed

3.)
Next I received a special character in my access token error. I had to add extra debugging to even see this error. Upon more googling, it looks like the value coming from the database needed to be url encoded before being sent to QBO.

So these 2 lines i modifed in the Services QBOApiCall method to add the encoding and then everything finally worked all the way through--

(add using System.Web; at top of Services)
token.AccessToken = HttpUtility.UrlEncode(token.AccessToken);
token.RealmId = HttpUtility.UrlEncode(token.RealmId);

It would be great if these could be incorporated in the download so others don't have to go through this :) It was a great learning experience though and thank you for getting us a .net core sample app for oauth2 and qbo, it is much appreciated.

connection is not working.

hi there.
It appears that when I go to the https://localhost:47331/connect/index to connect to the quickbooks service on the callback the app gets stuck in the https://localhost:47331/connect/index&code.......

Then the ConnectController login is not working, throwing an exception. When I try the .../qbo directly to create a customer the token is empty in the Services.cs QBOApiLogin method for some reason. I tried to resolve this but it appears that I am stuck with it. Is the code up to date?

Any help will be much appreciated.

Thanks

Get Method

Any example getting, for example, a list of accounts? Seems the example only works to create something in QuickBooks.

Gets stuck in login loop since Nov 13 due to HTTP 400 (Bad Request) in https://appconnections-aws.api.intuit.com/api/v2/connections/preauthorizations

return Challenge(new AuthenticationProperties() { RedirectUri = authorizeUrl });

Challenge result generates request with duplicated keys in query string:

Request URL: https://appcenter.intuit.com/connect/oauth2?client_id=CLEARED&response_type=code&scope=com.intuit.quickbooks.accounting&redirect_uri=https%3A%2F%2Flocalhost%3A44391%2Fconnect%2Findex&state=6437a43b8718b22e57dd459443ab2c366f0a568464b1a3fd8ea81ea5c86fd955&client_id=CLEARED&scope=&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A44391%2F&state=CfDJ8ACmen0w529OspUAXOmgvCIA90tVsNFNhiZXmQVgg49qcyeB5US1MkPls4jAPCWxbVrxYWJSpZYGf2NvPjXx8KmC8RSEiaZTV5eQHjWMi87M8e1mcVRpY-ejJCFX01JGr-oUAepAsOfs39t1wDTzBYWCRgVW3x4CoHMyhCqWX5ri5cgNC2MyB1hytI-9oqMpGc_mMm2oSbnRfZoFqJjgNB6970ZvKXLmTWVl7WdE-znuHivzn1LO6iLELs3bBNa0HKfhkEpkymnolwo5b9vmfa99wrRFpgEYk9F18ug3dU_nqxXouI1VyaRsrUGnU-wW7MmlnhZhlVH7z39y8myrbKLeYsEi-Lj3z5IAv0oD7AKzmbu_qs8t1W0fRxpj7F-Cd8RBPTshUwugka7KNuMXa25sFWP_70Kj7DHHCGD81grHvtAPB0WCa13lvOSbDr34aZEEBd_Ph8ttBmbfZieBNFAzwk_xYNXzXyFxMUY85EzQY4P3pDPJCxbGJYJpCg4lOdCWcu_W6n6eca3Jv_F028xFp0q3S00NXbzWWTW-ZHAo08qvwySOhdTO4kMc4dzE3zexrvDObvqcsMPyjhWNH3g

Request Method: GET

Status Code: 301 

Remote Address: 44.225.237.22:443

Referrer Policy: no-referrer-when-downgrade

 

Headers:

:authority: appcenter.intuit.com

:method: GET

:path: /connect/oauth2?client_id=CLEARED&response_type=code&scope=com.intuit.quickbooks.accounting&redirect_uri=https%3A%2F%2Flocalhost%3A44391%2Fconnect%2Findex&state=6437a43b8718b22e57dd459443ab2c366f0a568464b1a3fd8ea81ea5c86fd955&client_id=CLEARED&scope=&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A44391%2F&state=CfDJ8ACmen0w529OspUAXOmgvCIA90tVsNFNhiZXmQVgg49qcyeB5US1MkPls4jAPCWxbVrxYWJSpZYGf2NvPjXx8KmC8RSEiaZTV5eQHjWMi87M8e1mcVRpY-ejJCFX01JGr-oUAepAsOfs39t1wDTzBYWCRgVW3x4CoHMyhCqWX5ri5cgNC2MyB1hytI-9oqMpGc_mMm2oSbnRfZoFqJjgNB6970ZvKXLmTWVl7WdE-znuHivzn1LO6iLELs3bBNa0HKfhkEpkymnolwo5b9vmfa99wrRFpgEYk9F18ug3dU_nqxXouI1VyaRsrUGnU-wW7MmlnhZhlVH7z39y8myrbKLeYsEi-Lj3z5IAv0oD7AKzmbu_qs8t1W0fRxpj7F-Cd8RBPTshUwugka7KNuMXa25sFWP_70Kj7DHHCGD81grHvtAPB0WCa13lvOSbDr34aZEEBd_Ph8ttBmbfZieBNFAzwk_xYNXzXyFxMUY85EzQY4P3pDPJCxbGJYJpCg4lOdCWcu_W6n6eca3Jv_F028xFp0q3S00NXbzWWTW-ZHAo08qvwySOhdTO4kMc4dzE3zexrvDObvqcsMPyjhWNH3g

:scheme: https

accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3

accept-encoding: gzip, deflate, br

accept-language: en-CA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7,ru;q=0.6

cache-control: no-cache

pragma: no-cache

referer: https://localhost:44391/Connect/Home

sec-fetch-mode: navigate

sec-fetch-site: cross-site

sec-fetch-user: ?1

upgrade-insecure-requests: 1

user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36

 

Query String Parameters:

client_id: CLEARED

response_type: code

scope: com.intuit.quickbooks.accounting

redirect_uri: https://localhost:44391/connect/index

state: 6437a43b8718b22e57dd459443ab2c366f0a568464b1a3fd8ea81ea5c86fd955

client_id: CLEARED

scope: 

response_type: code

redirect_uri: https://localhost:44391/

state: CfDJ8ACmen0w529OspUAXOmgvCIA90tVsNFNhiZXmQVgg49qcyeB5US1MkPls4jAPCWxbVrxYWJSpZYGf2NvPjXx8KmC8RSEiaZTV5eQHjWMi87M8e1mcVRpY-ejJCFX01JGr-oUAepAsOfs39t1wDTzBYWCRgVW3x4CoHMyhCqWX5ri5cgNC2MyB1hytI-9oqMpGc_mMm2oSbnRfZoFqJjgNB6970ZvKXLmTWVl7WdE-znuHivzn1LO6iLELs3bBNa0HKfhkEpkymnolwo5b9vmfa99wrRFpgEYk9F18ug3dU_nqxXouI1VyaRsrUGnU-wW7MmlnhZhlVH7z39y8myrbKLeYsEi-Lj3z5IAv0oD7AKzmbu_qs8t1W0fRxpj7F-Cd8RBPTshUwugka7KNuMXa25sFWP_70Kj7DHHCGD81grHvtAPB0WCa13lvOSbDr34aZEEBd_Ph8ttBmbfZieBNFAzwk_xYNXzXyFxMUY85EzQY4P3pDPJCxbGJYJpCg4lOdCWcu_W6n6eca3Jv_F028xFp0q3S00NXbzWWTW-ZHAo08qvwySOhdTO4kMc4dzE3zexrvDObvqcsMPyjhWNH3g

And then after clicking "Sign in" button gets HTTP 400 (Bad Request)

Request URL: https://appconnections-aws.api.intuit.com/api/v2/connections/preauthorizations

Request Method: POST

Status Code: 400 

Remote Address: 52.37.45.219:443

Referrer Policy: no-referrer-when-downgrade

 

Headers:

:authority: appconnections-aws.api.intuit.com

:method: POST

:path: /api/v2/connections/preauthorizations

:scheme: https

accept: application/json

accept-encoding: gzip, deflate, br

accept-language: en-CA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7,ru;q=0.6

authorization: Intuit_APIKey intuit_apikey=prdakyresrdKGQdEsCeZkU8cBzSKIPBEzA80IHvN,intuit_apikey_version=1.0

cache-control: no-cache

content-length: 968

content-type: application/json

intuit_tid: 69234aeb-322e-4059-841c-b96b6aea9d07

origin: https://appcenter.intuit.com

pragma: no-cache

referer: https://appcenter.intuit.com/app/connect/oauth2?client_id=CLEARED&response_type=code&scope=com.intuit.quickbooks.accounting&redirect_uri=https%3A%2F%2Flocalhost%3A44391%2Fconnect%2Findex&state=6437a43b8718b22e57dd459443ab2c366f0a568464b1a3fd8ea81ea5c86fd955&client_id=CLEARED&scope=&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A44391%2F&state=CfDJ8ACmen0w529OspUAXOmgvCIA90tVsNFNhiZXmQVgg49qcyeB5US1MkPls4jAPCWxbVrxYWJSpZYGf2NvPjXx8KmC8RSEiaZTV5eQHjWMi87M8e1mcVRpY-ejJCFX01JGr-oUAepAsOfs39t1wDTzBYWCRgVW3x4CoHMyhCqWX5ri5cgNC2MyB1hytI-9oqMpGc_mMm2oSbnRfZoFqJjgNB6970ZvKXLmTWVl7WdE-znuHivzn1LO6iLELs3bBNa0HKfhkEpkymnolwo5b9vmfa99wrRFpgEYk9F18ug3dU_nqxXouI1VyaRsrUGnU-wW7MmlnhZhlVH7z39y8myrbKLeYsEi-Lj3z5IAv0oD7AKzmbu_qs8t1W0fRxpj7F-Cd8RBPTshUwugka7KNuMXa25sFWP_70Kj7DHHCGD81grHvtAPB0WCa13lvOSbDr34aZEEBd_Ph8ttBmbfZieBNFAzwk_xYNXzXyFxMUY85EzQY4P3pDPJCxbGJYJpCg4lOdCWcu_W6n6eca3Jv_F028xFp0q3S00NXbzWWTW-ZHAo08qvwySOhdTO4kMc4dzE3zexrvDObvqcsMPyjhWNH3g&cid=google.com%20%5Bref%5D

sec-fetch-mode: cors

sec-fetch-site: same-site

user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36

 

Request Payload:

{

client_id: [

"CLEARED",

"CLEARED"

],

redirect_uri: [

"https://localhost:44391/connect/index",

"https://localhost:44391/"

],

response_type: [

"code",

"code"

],

scope: [

"com.intuit.quickbooks.accounting",

""

],

state: [

0: "6437a43b8718b22e57dd459443ab2c366f0a568464b1a3fd8ea81ea5c86fd955",

1: "CfDJ8ACmen0w529OspUAXOmgvCIA90tVsNFNhiZXmQVgg49qcyeB5US1MkPls4jAPCWxbVrxYWJSpZYGf2NvPjXx8KmC8RSEiaZTV5eQHjWMi87M8e1mcVRpY-ejJCFX01JGr-oUAepAsOfs39t1wDTzBYWCRgVW3x4CoHMyhCqWX5ri5cgNC2MyB1hytI-9oqMpGc_mMm2oSbnRfZoFqJjgNB6970ZvKXLmTWVl7WdE-znuHivzn1LO6iLELs3bBNa0HKfhkEpkymnolwo5b9vmfa99wrRFpgEYk9F18ug3dU_nqxXouI1VyaRsrUGnU-wW7MmlnhZhlVH7z39y8myrbKLeYsEi-Lj3z5IAv0oD7AKzmbu_qs8t1W0fRxpj7F-Cd8RBPTshUwugka7KNuMXa25sFWP_70Kj7DHHCGD81grHvtAPB0WCa13lvOSbDr34aZEEBd_Ph8ttBmbfZieBNFAzwk_xYNXzXyFxMUY85EzQY4P3pDPJCxbGJYJpCg4lOdCWcu_W6n6eca3Jv_F028xFp0q3S00NXbzWWTW-ZHAo08qvwySOhdTO4kMc4dzE3zexrvDObvqcsMPyjhWNH3g"

]

}

Error 403 when creating a customer

Appears to do nothing when creating a customer. A trace shows that an IdsException is being thrown which gives Error 403 Forbidden. "Ids service endpoint was not found".

My workaround is to edit Services.cs method QBOApiCall and insert a line
before apiCallFunction() to set the BaseUrl.

ServiceContext context = new ServiceContext(token.RealmId, IntuitServicesType.QBO, reqValidator,configurationProvider);
context.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/";
apiCallFunction(context);

A better fix would be for Quickbooks dev to to update ServiceContext to read an entry from appsettings.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.