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

Oauth2 #59

Closed
wants to merge 8 commits into from
Closed

Oauth2 #59

wants to merge 8 commits into from

Conversation

zzk
Copy link

@zzk zzk commented Apr 27, 2015

Implement oauth2 token based authorization into ruby_odata. Heavily depends on #58.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.19%) to 96.92% when pulling 2d4759c on zzk:oauth2 into 595f15d on visoft:master.

@exadeci
Copy link

exadeci commented Mar 22, 2016

Any update on that ?

@visoft
Copy link
Owner

visoft commented Mar 22, 2016

This was released as v0.2.0.beta. There are some bugs still in it. I'm hoping to have time to work on this in the near future. If you have time and are willing to add a PR, that would be awesome!

@exadeci
Copy link

exadeci commented Mar 24, 2016

It doesn't seems to work with https://msdn.microsoft.com/en-us/library/mt593051.aspx for some reason it can't parse it Nokogiri::XML::XPath::SyntaxError: Undefined namespace prefix: edmx:Edmx/edmx:DataServices/* so I guess I won't be using it.

@visoft
Copy link
Owner

visoft commented Mar 24, 2016

It looks like that's OData version 4. Currently ruby_odata doesn't support 4.0, but I'd love to change that.

@visoft visoft mentioned this pull request Oct 12, 2016
@wtfiwtz
Copy link

wtfiwtz commented Oct 4, 2017

After a lot of trouble I got access to Dynamics 365 on Azure Active Directory through the Web API and oauth2 authentication...

https://github.com/AzureAD/azure-activedirectory-library-for-ruby

With the secret sauce...

username      = 'admin@tenant.onmicrosoft.com'
password      = 'xxxxxxxxxxxx'
client_id     = 'xxxxx-xxxx-xxx-xxxxxx-xxxxxxx'
client_secret = 'xxxXXXxxXXXxxxXXXxxXXXXXXXXxxxxxx='
tenant        = 'tenant.onmicrosoft.com'
user_cred     = ADAL::UserCredential.new(username, password)
client_cred   = ADAL::ClientCredential.new(client_id, client_secret)
context       = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, tenant)
resource      = "https://domain.crm6.dynamics.com"
tokens        = context.acquire_token_for_user(resource, client_cred, user_cred)

# add the access token to the request header
callback = Proc.new { |r| r.headers["Authorization"] = "Bearer #{tokens.access_token}" }

and

def request(uri, access_token)
  auth = "Bearer #{access_token}"
  Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json; charset=utf-8',
    'Authorization' => auth,
    'OData-MaxVersion' => '4.0',
    'OData-Version' => '4.0',
    'Accept' => 'application/json',
    'Prefer' => 'odata.include-annotations="*"')
end

Microsoft has some ODATA v4 suppport implemented here:
https://github.com/microsoftgraph/msgraph-sdk-ruby

Not sure if I will use this for Dynamics 365 though... but at least I got past the oauth 2.0 hurdles.

@wtfiwtz
Copy link

wtfiwtz commented Oct 4, 2017

For the SOAP API (instead of Web API) on Dynamics you can use this library too: https://github.com/TinderBox/dynamics_crm

@exadeci
Copy link

exadeci commented Oct 4, 2017

@wtfiwtz It should be the parent repository https://github.com/TinderBox/dynamics_crm the one you've linked is mine with a custom change.

@wtfiwtz
Copy link

wtfiwtz commented Oct 4, 2017

Thanks @exadeci... I meant to link the parent but did that one accidentally!

@zzk zzk closed this Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants