adal 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +7 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +25 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +97 -0
  8. data/Rakefile +39 -0
  9. data/adal.gemspec +52 -0
  10. data/contributing.md +127 -0
  11. data/lib/adal.rb +24 -0
  12. data/lib/adal/authentication_context.rb +202 -0
  13. data/lib/adal/authentication_parameters.rb +126 -0
  14. data/lib/adal/authority.rb +165 -0
  15. data/lib/adal/cache_driver.rb +171 -0
  16. data/lib/adal/cached_token_response.rb +190 -0
  17. data/lib/adal/client_assertion.rb +63 -0
  18. data/lib/adal/client_assertion_certificate.rb +89 -0
  19. data/lib/adal/client_credential.rb +46 -0
  20. data/lib/adal/core_ext.rb +26 -0
  21. data/lib/adal/core_ext/hash.rb +34 -0
  22. data/lib/adal/jwt_parameters.rb +39 -0
  23. data/lib/adal/logger.rb +90 -0
  24. data/lib/adal/logging.rb +98 -0
  25. data/lib/adal/memory_cache.rb +95 -0
  26. data/lib/adal/mex_request.rb +52 -0
  27. data/lib/adal/mex_response.rb +141 -0
  28. data/lib/adal/noop_cache.rb +38 -0
  29. data/lib/adal/oauth_request.rb +76 -0
  30. data/lib/adal/request_parameters.rb +48 -0
  31. data/lib/adal/self_signed_jwt_factory.rb +96 -0
  32. data/lib/adal/templates/rst.13.xml.erb +35 -0
  33. data/lib/adal/templates/rst.2005.xml.erb +32 -0
  34. data/lib/adal/token_request.rb +231 -0
  35. data/lib/adal/token_response.rb +144 -0
  36. data/lib/adal/user_assertion.rb +57 -0
  37. data/lib/adal/user_credential.rb +152 -0
  38. data/lib/adal/user_identifier.rb +83 -0
  39. data/lib/adal/user_information.rb +49 -0
  40. data/lib/adal/util.rb +49 -0
  41. data/lib/adal/version.rb +36 -0
  42. data/lib/adal/wstrust_request.rb +100 -0
  43. data/lib/adal/wstrust_response.rb +168 -0
  44. data/lib/adal/xml_namespaces.rb +64 -0
  45. data/samples/authorization_code_example/README.md +10 -0
  46. data/samples/authorization_code_example/web_app.rb +139 -0
  47. data/samples/client_assertion_certificate_example/README.md +42 -0
  48. data/samples/client_assertion_certificate_example/app.rb +55 -0
  49. data/samples/on_behalf_of_example/README.md +35 -0
  50. data/samples/on_behalf_of_example/native_app.rb +52 -0
  51. data/samples/on_behalf_of_example/web_api.rb +71 -0
  52. data/samples/user_credentials_example/README.md +7 -0
  53. data/samples/user_credentials_example/app.rb +52 -0
  54. data/spec/adal/authentication_context_spec.rb +186 -0
  55. data/spec/adal/authentication_parameters_spec.rb +107 -0
  56. data/spec/adal/authority_spec.rb +122 -0
  57. data/spec/adal/cache_driver_spec.rb +191 -0
  58. data/spec/adal/cached_token_response_spec.rb +148 -0
  59. data/spec/adal/client_assertion_certificate_spec.rb +113 -0
  60. data/spec/adal/client_assertion_spec.rb +38 -0
  61. data/spec/adal/core_ext/hash_spec.rb +47 -0
  62. data/spec/adal/logging_spec.rb +48 -0
  63. data/spec/adal/memory_cache_spec.rb +107 -0
  64. data/spec/adal/mex_request_spec.rb +57 -0
  65. data/spec/adal/mex_response_spec.rb +143 -0
  66. data/spec/adal/self_signed_jwt_factory_spec.rb +63 -0
  67. data/spec/adal/token_request_spec.rb +150 -0
  68. data/spec/adal/token_response_spec.rb +102 -0
  69. data/spec/adal/user_credential_spec.rb +125 -0
  70. data/spec/adal/user_identifier_spec.rb +115 -0
  71. data/spec/adal/wstrust_request_spec.rb +51 -0
  72. data/spec/adal/wstrust_response_spec.rb +152 -0
  73. data/spec/fixtures/mex/insecureaddress.xml +924 -0
  74. data/spec/fixtures/mex/invalid_namespaces.xml +916 -0
  75. data/spec/fixtures/mex/malformed.xml +914 -0
  76. data/spec/fixtures/mex/microsoft.xml +916 -0
  77. data/spec/fixtures/mex/multiple_endpoints.xml +922 -0
  78. data/spec/fixtures/mex/no_matching_bindings.xml +916 -0
  79. data/spec/fixtures/mex/no_username_token_policies.xml +914 -0
  80. data/spec/fixtures/mex/no_wstrust_endpoints.xml +838 -0
  81. data/spec/fixtures/mex/only_13.xml +842 -0
  82. data/spec/fixtures/mex/only_2005.xml +842 -0
  83. data/spec/fixtures/oauth/error.json +1 -0
  84. data/spec/fixtures/oauth/success.json +1 -0
  85. data/spec/fixtures/oauth/success_with_id_token.json +1 -0
  86. data/spec/fixtures/wstrust/error.xml +24 -0
  87. data/spec/fixtures/wstrust/invalid_namespaces.xml +136 -0
  88. data/spec/fixtures/wstrust/missing_security_tokens.xml +90 -0
  89. data/spec/fixtures/wstrust/success.xml +136 -0
  90. data/spec/fixtures/wstrust/token.xml +1 -0
  91. data/spec/fixtures/wstrust/too_many_security_tokens.xml +219 -0
  92. data/spec/fixtures/wstrust/unrecognized_token_type.xml +136 -0
  93. data/spec/fixtures/wstrust/wstrust.13.xml +1 -0
  94. data/spec/fixtures/wstrust/wstrust.2005.xml +89 -0
  95. data/spec/spec_helper.rb +53 -0
  96. data/spec/support/fake_data.rb +40 -0
  97. data/spec/support/fake_token_endpoint.rb +108 -0
  98. metadata +265 -0
@@ -0,0 +1,136 @@
1
+ <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
2
+ xmlns:a="http://www.w3.org/2005/08/addressing"
3
+ xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
4
+ <s:Header>
5
+ <a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RSTRC/IssueFinal</a:Action>
6
+ <o:Security s:mustUnderstand="1"
7
+ xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
8
+ <u:Timestamp u:Id="_0">
9
+ <u:Created>2014-10-11T01:57:52.927Z</u:Created>
10
+ <u:Expires>2014-10-11T02:02:52.927Z</u:Expires>
11
+ </u:Timestamp>
12
+ </o:Security>
13
+ </s:Header>
14
+ <s:Body>
15
+ <trust:RequestSecurityTokenResponseCollection
16
+ xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
17
+ <trust:RequestSecurityTokenResponse>
18
+ <trust:Lifetime>
19
+ <wsu:Created
20
+ xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2014-10-11T01:57:52.802Z</wsu:Created>
21
+ <wsu:Expires
22
+ xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2014-10-11T02:57:52.802Z</wsu:Expires>
23
+ </trust:Lifetime>
24
+ <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
25
+ <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
26
+ <wsa:Address>urn:federation:MicrosoftOnline</wsa:Address>
27
+ </wsa:EndpointReference>
28
+ </wsp:AppliesTo>
29
+ <trust:RequestedSecurityToken>
30
+ <saml:Assertion MajorVersion="1" MinorVersion="1"
31
+ AssertionID="_3ad77714-87a7-4ec5-b3e8-dfd2ef68a49e" Issuer="urn:federation:MSFT"
32
+ IssueInstant="2014-10-11T01:57:52.927Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
33
+ <saml:Conditions NotBefore="2014-10-11T01:57:52.802Z"
34
+ NotOnOrAfter="2014-10-11T02:57:52.802Z">
35
+ <saml:AudienceRestrictionCondition>
36
+ <saml:Audience>urn:federation:MicrosoftOnline</saml:Audience>
37
+ </saml:AudienceRestrictionCondition>
38
+ </saml:Conditions>
39
+ <saml:AttributeStatement>
40
+ <saml:Subject>
41
+ <saml:NameIdentifier
42
+ Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">11111</saml:NameIdentifier>
43
+ <saml:SubjectConfirmation>
44
+ <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer
45
+ </saml:ConfirmationMethod>
46
+ </saml:SubjectConfirmation>
47
+ </saml:Subject>
48
+ <saml:Attribute AttributeName="UPN"
49
+ AttributeNamespace="http://schemas.xmlsoap.org/claims">
50
+ <saml:AttributeValue>sdfb4@vsfdbs.com</saml:AttributeValue>
51
+ </saml:Attribute>
52
+ <saml:Attribute AttributeName="objectGUID"
53
+ AttributeNamespace="http://tempuri.com">
54
+ <saml:AttributeValue>sefgbw4w4tbwrtb==
55
+ </saml:AttributeValue>
56
+ </saml:Attribute>
57
+ <saml:Attribute AttributeName="PersonnelNumber"
58
+ AttributeNamespace="http://schemas.xmlsoap.org/claims">
59
+ <saml:AttributeValue>11111</saml:AttributeValue>
60
+ </saml:Attribute>
61
+ <saml:Attribute AttributeName="ImmutableID"
62
+ AttributeNamespace="http://schemas.microsoft.com/LiveID/Federation/2008/05">
63
+ <saml:AttributeValue>11111</saml:AttributeValue>
64
+ </saml:Attribute>
65
+ <saml:Attribute AttributeName="insidecorporatenetwork"
66
+ AttributeNamespace="http://schemas.microsoft.com/ws/2012/01">
67
+ <saml:AttributeValue>true</saml:AttributeValue>
68
+ </saml:Attribute>
69
+ <saml:Attribute AttributeName="psso"
70
+ AttributeNamespace="http://schemas.microsoft.com/2014/03">
71
+ <saml:AttributeValue>true</saml:AttributeValue>
72
+ </saml:Attribute>
73
+ </saml:AttributeStatement>
74
+ <saml:AuthenticationStatement
75
+ AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
76
+ AuthenticationInstant="2014-10-11T01:57:52.786Z">
77
+ <saml:Subject>
78
+ <saml:NameIdentifier
79
+ Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">11111</saml:NameIdentifier>
80
+ <saml:SubjectConfirmation>
81
+ <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer
82
+ </saml:ConfirmationMethod>
83
+ </saml:SubjectConfirmation>
84
+ </saml:Subject>
85
+ </saml:AuthenticationStatement>
86
+ <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
87
+ <ds:SignedInfo>
88
+ <ds:CanonicalizationMethod
89
+ Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
90
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
91
+ <ds:Reference URI="#_3ad77714-87a7-4ec5-b3e8-dfd2ef68a49e">
92
+ <ds:Transforms>
93
+ <ds:Transform
94
+ Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
95
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
96
+ </ds:Transforms>
97
+ <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
98
+ <ds:DigestValue>11112412434fgvwefb24rb=</ds:DigestValue>
99
+ </ds:Reference>
100
+ </ds:SignedInfo>
101
+ <ds:SignatureValue>yc2hltEY1z/0zgEdUKdIo9K8BAauLYCvEM21Jrasdnvkadsjv9834759384utfhwrgEDSDGSDFG34543fFFwdffeeeeCfnoRal7Q1PXtxwsDqg/maesA7/1eYG75Q6/MyB5s+GZqUDK5Sif1XXseTe3hbocz/dMfVIeHKZ/BJ9iKdjI+WhDJspJ282sCu9e31h0CKEEgHwwe3U+0iwtwXrBxJKi9wNrrShez7CW+18jz2bQ+hFxsLYpuXSskOgeB6wza5BR9QjLHjjntqchVZOgZNQzmnULQBXIbPHGvrcKZZ1+05y27505B8T1jOopN6ncdic2b3tt712n/lDbtQCBKOUp5A0ZIP8nupkUE4lvIE0qFiETrWFKbRKgNLzPSS8Fb0ITuq5FPQRNDZkYebVqBvQavd7T8qx9RnhXwJNYBABxZ2NgicCT1QnAhPwyU4vvMaSeCbguAsbO0z6IM9Y6pzLe6eehvzh2/WfIckEExeHvPTEZZWMiA16msBSWLX+NkVMLfVBj8GA2sK7Qj4wnvK6ip+8x5PBl5z3Ra8p7MXsDVnunZcl5LnjBM7Z0puX9vT79xVuJ7+q3jD6GRjiH0XZr4yZXCJk2Ipfq9P4S+8fT50=
102
+ </ds:SignatureValue>
103
+ <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
104
+ <X509Data>
105
+ <X509Certificate>vwbeiurkjbhvnsfbMMWEFGVWERBwbdfefwbbFowITEfMB0GA1UEAxMWbXNmdC5zdHMubWljcm9zb2Z0LmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMsKK87jKV6UdjZWE5gu2lUecEJeBH35aEG89U9fAXqRIbsmkAgnZAqtmD3dw4W0edvOMW0YxLejvHpxrrei4Hc3KOYczFaiJGOxeir6Fymk5cOJ0x3ioJGSCn/X0J0vka6sUijwUlFzaqOyTO5YP23AzSu2a39SUxBCVNqgkGrbjMp4xl1LP6rYrNc1QG/aBGvT0od0oXF4Hy5uiCxqq49Wb+QjCyJ76+1kzkWHTK18r8vOG9GxfWfNeshT9W9XoT9ChgRcxIHt/Y2ZUrOT86ldpakld58gTq1E0l5jho3CZPAnZjnwBhYv9bUgsgwHUU29Ceig/iqdjUDzS50F4pn2pcncoWGmrQP3hOEvJRCs0BWz6+VW/ATV5TGknsLDfq89c5b69haZ3fiDQmU+RZQBIsLEcrRs3Vyld++rmM7OdfZ4CAbo8l3F4ONpHczWfNKhGnor4GH0vC6G5gR3otWCdM6bcrNCYjm4PEVaF0I5+94PvJ2SkaGL4k86u+Ns4OpFLGawC5D3bq0SPMgsUWbXzq4VXq946fewWLV4Jh4mvRkVdsb1egk78rzQdpeqfiq9Ax6W6wRLCIFUiicymITQw/mn646OvwR2mTMc2M+BfW9a35MwfZfyMG/PdZc7nl2Alvuiw1Wk6M3C2xcS8Hpu9unnacXujRr/FbgnaKwnAgMBAAGjdTBzMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATBSBgNVHQEESzBJgBBsOlmxcrgqKZ1x+s8zuEDRoSMwITEfMB0GA1UEAxMWbXNmdC5zdHMubWljcm9zb2Z0LmNvbYIQYvo/wNRpcL5JZi8e/Z4hBzANBgkqhkiG9w0BAQsFAAOCAgEAQbiCZJWFH9zaGaPlT77Jq9bWoH6fqZRrNIDuVXM7h+g7E8Xj5Demi16WrRSTR8Ff1uNV0n5tdbLu4C9rEU4RrZjFOJXGGsQZD85y8Jq3tcZ6RZSU6ie3tzvpl5Yhe0o1xfuUvI43VxJWFzW7LHzHyzoDeFNhSuplWfGkQfdjs9yGLTYflIDVCigXv94Wv949HckiG1+PST9ai9jST6NCkeqElm5zoZHxo+haYIRMma4lL7/AO3uYhey5bKYyIHyWTAZcJBKqO2RrWuOtZWthK/gL0yTeGrGXFQvHbfUwEA/lBdUka/x8m59hzSCS2c0f/GZbrBGq6mOrl4NSrJSck4KJnQDbdYzyP2kIVWwjlYMNbFWXE0e2lxm6T28Znhh0wtqrBDyQIxDFpt/bdw9I5OsXmXvjRYlVXP1gmHebuhL9wA3A9BKUaTNf2BTfvWdYnBwbRq98vB4RSAwWRLjv9bizB9JkmMUSmPS9Z5juPMmkbTpcmn8RUUPLGDpuFYMB0dXpGtG+oJ40wHeYZCvfBU1tuXuB+RTxkPsXzF4WEf6sei0VCgs+ir0mULF9L++Bc0INn9VpZoOpDE9pX7jMn9jkutClaxVOirysvYcOAy092MHo3uR6opH9U9vzWJrQULxPOdT+GVwLJ2ZgSmYC14tsr37vbC8WAD5E1zyfGPU=
106
+ </X509Certificate>
107
+ </X509Data>
108
+ </KeyInfo>
109
+ </ds:Signature>
110
+ </saml:Assertion>
111
+ </trust:RequestedSecurityToken>
112
+ <trust:RequestedAttachedReference>
113
+ <o:SecurityTokenReference
114
+ k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1"
115
+ xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
116
+ xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
117
+ <o:KeyIdentifier
118
+ ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">_3ad77714-87a7-4ec5-b3e8-dfd2ef68a49e</o:KeyIdentifier>
119
+ </o:SecurityTokenReference>
120
+ </trust:RequestedAttachedReference>
121
+ <trust:RequestedUnattachedReference>
122
+ <o:SecurityTokenReference
123
+ k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1"
124
+ xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
125
+ xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
126
+ <o:KeyIdentifier
127
+ ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">_3ad77714-87a7-4ec5-b3e8-dfd2ef68a49e</o:KeyIdentifier>
128
+ </o:SecurityTokenReference>
129
+ </trust:RequestedUnattachedReference>
130
+ <trust:TokenType>urn:oasis:names:tc:SAML:3.0:assertion</trust:TokenType>
131
+ <trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType>
132
+ <trust:KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
133
+ </trust:RequestSecurityTokenResponse>
134
+ </trust:RequestSecurityTokenResponseCollection>
135
+ </s:Body>
136
+ </s:Envelope>
@@ -0,0 +1 @@
1
+ <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RSTRC/IssueFinal</a:Action><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2015-07-31T18:52:50.806Z</u:Created><u:Expires>2015-07-31T18:57:50.806Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><trust:RequestSecurityTokenResponseCollection xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"><trust:RequestSecurityTokenResponse><trust:Lifetime><wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-07-31T18:52:50.806Z</wsu:Created><wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-07-31T19:52:50.806Z</wsu:Expires></trust:Lifetime><wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"><wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Address>urn:federation:MicrosoftOnline</wsa:Address></wsa:EndpointReference></wsp:AppliesTo><trust:RequestedSecurityToken><saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_57806901-e325-431f-827b-28dc3f81f007" Issuer="http://fs.ajmichael.net/adfs/services/trust" IssueInstant="2015-07-31T18:52:50.806Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"><saml:Conditions NotBefore="2015-07-31T18:52:50.806Z" NotOnOrAfter="2015-07-31T19:52:50.806Z"><saml:AudienceRestrictionCondition><saml:Audience>urn:federation:MicrosoftOnline</saml:Audience></saml:AudienceRestrictionCondition></saml:Conditions><saml:AttributeStatement><saml:Subject><saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">vtgQONppjEaJq77vvbpJWA==</saml:NameIdentifier><saml:SubjectConfirmation><saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod></saml:SubjectConfirmation></saml:Subject><saml:Attribute AttributeName="UPN" AttributeNamespace="http://schemas.xmlsoap.org/claims"><saml:AttributeValue>aaron@ajmichael.net</saml:AttributeValue></saml:Attribute><saml:Attribute AttributeName="ImmutableID" AttributeNamespace="http://schemas.microsoft.com/LiveID/Federation/2008/05"><saml:AttributeValue>vtgQONppjEaJq77vvbpJWA==</saml:AttributeValue></saml:Attribute></saml:AttributeStatement><saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2015-07-31T18:52:50.806Z"><saml:Subject><saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">vtgQONppjEaJq77vvbpJWA==</saml:NameIdentifier><saml:SubjectConfirmation><saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod></saml:SubjectConfirmation></saml:Subject></saml:AuthenticationStatement><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#_57806901-e325-431f-827b-28dc3f81f007"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>oF5D0U4UJToa/rNQgaddWjBzEJ0=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>PpNWCDILvv9BX5yAkJDCwIEr6AHh9ltAPyp8nvHuiIaanyAgLi755MNylLBWm2PbW7FlJ4O4izHmMhSELcsh4yGni1FQrqJLuZ7SIcxm/7D8Nh7L+XmhAh9zS2AVStbV8ZOC083ItmnDcOfagcvYBQa69aW37RBNJj67o4sHS0GDb9EAGqP9d/GyYcpCmo3X8AQ8DK9f7KIKQSRXseUQFkAUP9zJ+XS/QGb/ByiXbQCBIGB50R6smdJW9IDG73frUfWkD6kO2v8oLMsXddmMu54Y/CUKzxyVb2Sg4xPWEqExBb4Z/WlV1kDU6lfx6jtPTxNorSEXnFKeLYDuWmgDdQ==</ds:SignatureValue><KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"><X509Data><X509Certificate>MIIC3DCCAcSgAwIBAgIQZK0UpOPhlpxBNKzZ8XOwRzANBgkqhkiG9w0BAQsFADAqMSgwJgYDVQQDEx9BREZTIFNpZ25pbmcgLSBmcy5ham1pY2hhZWwubmV0MB4XDTE1MDcwMjIxMzYyOVoXDTE2MDcwMTIxMzYyOVowKjEoMCYGA1UEAxMfQURGUyBTaWduaW5nIC0gZnMuYWptaWNoYWVsLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyCCmkytGlVsg8H2zUo3zZ8p/2tuq/f1QOw9h9rh3EKaJrX4+Hk60rzjNiwmSfnpqcYDS7MPKTX2UdngV6HZsnEQD5S2vaNTncGIkyvAi6jAUo9fYfuSIZxQyoP6wFqTMYHrHJhjZEuExPNAKEFmR0oozSzCFOZH0oJCr1b1jwb5Fi7M1uN98DPbRQg0CbTdV2EJzj2cnMX7v1aohwUg8rUo3yvexLuvcJSXy4kRWCNRTtVOo57NeE2pECdlCZQOMCnpps7AfaEUkLQL8Jbi8lJyNZ65I19+wKYSb1mx60c2rotgkQIN6v5/WgnXdA3Dok9gbjlqoK9Ew3rzAmr4q8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEACsiXJk+V+rBOJJkaVss8qDqysT2H6PcV6vjWs+fk84edYqhpNz9wimLOa/afQSVgcfMAbs6/CG3STmGRvQ+wDhYsVBzX3hzur741IYQclz9eEJtSrPNG04/zqq2/9LP81reIEksfKhgPho33PYop3cSorO8ogbxm10/bFgi99Lz1tTJkxpGhjxOdrMrZ5gU2r9NfyeL6Z9hmiixHQXruQdQSTeUsOVnx97mLO9fjKbeeeGrI5x8xsVWYDqRlhfXamwaglXu8ptf7frY/+FLoVKSAlGSV+GMw2Q53s4h91o4hPsNxanZD474n2soP3MKqeIyqVtafboooZ85PGh2kvg==</X509Certificate></X509Data></KeyInfo></ds:Signature></saml:Assertion></trust:RequestedSecurityToken><trust:RequestedAttachedReference><o:SecurityTokenReference k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"><o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">_57806901-e325-431f-827b-28dc3f81f007</o:KeyIdentifier></o:SecurityTokenReference></trust:RequestedAttachedReference><trust:RequestedUnattachedReference><o:SecurityTokenReference k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"><o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">_57806901-e325-431f-827b-28dc3f81f007</o:KeyIdentifier></o:SecurityTokenReference></trust:RequestedUnattachedReference><trust:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</trust:TokenType><trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType><trust:KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType></trust:RequestSecurityTokenResponse></trust:RequestSecurityTokenResponseCollection></s:Body></s:Envelope>
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0"?>
2
+ <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <s:Header>
4
+ <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue</a:Action>
5
+ <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
6
+ <u:Timestamp u:Id="_0">
7
+ <u:Created>2015-07-30T21:08:29.919Z</u:Created>
8
+ <u:Expires>2015-07-30T21:13:29.919Z</u:Expires>
9
+ </u:Timestamp>
10
+ </o:Security>
11
+ </s:Header>
12
+ <s:Body>
13
+ <t:RequestSecurityTokenResponse xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
14
+ <t:Lifetime>
15
+ <wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-07-30T21:08:29.919Z</wsu:Created>
16
+ <wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-07-30T22:08:29.919Z</wsu:Expires>
17
+ </t:Lifetime>
18
+ <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
19
+ <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
20
+ <wsa:Address>urn:federation:MicrosoftOnline</wsa:Address>
21
+ </wsa:EndpointReference>
22
+ </wsp:AppliesTo>
23
+ <t:RequestedSecurityToken>
24
+ <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" MajorVersion="1" MinorVersion="1" AssertionID="_ba16587e-5f6c-4c2f-bad6-20767143844f" Issuer="http://fs.ajmichael.net/adfs/services/trust" IssueInstant="2015-07-30T21:08:29.919Z">
25
+ <saml:Conditions NotBefore="2015-07-30T21:08:29.919Z" NotOnOrAfter="2015-07-30T22:08:29.919Z">
26
+ <saml:AudienceRestrictionCondition>
27
+ <saml:Audience>urn:federation:MicrosoftOnline</saml:Audience>
28
+ </saml:AudienceRestrictionCondition>
29
+ </saml:Conditions>
30
+ <saml:AttributeStatement>
31
+ <saml:Subject>
32
+ <saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">vtgQONppjEaJq77vvbpJWA==</saml:NameIdentifier>
33
+ <saml:SubjectConfirmation>
34
+ <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod>
35
+ </saml:SubjectConfirmation>
36
+ </saml:Subject>
37
+ <saml:Attribute AttributeName="UPN" AttributeNamespace="http://schemas.xmlsoap.org/claims">
38
+ <saml:AttributeValue>aaron@ajmichael.net</saml:AttributeValue>
39
+ </saml:Attribute>
40
+ <saml:Attribute AttributeName="ImmutableID" AttributeNamespace="http://schemas.microsoft.com/LiveID/Federation/2008/05">
41
+ <saml:AttributeValue>vtgQONppjEaJq77vvbpJWA==</saml:AttributeValue>
42
+ </saml:Attribute>
43
+ </saml:AttributeStatement>
44
+ <saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2015-07-30T21:08:29.919Z">
45
+ <saml:Subject>
46
+ <saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">vtgQONppjEaJq77vvbpJWA==</saml:NameIdentifier>
47
+ <saml:SubjectConfirmation>
48
+ <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod>
49
+ </saml:SubjectConfirmation>
50
+ </saml:Subject>
51
+ </saml:AuthenticationStatement>
52
+ <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
53
+ <ds:SignedInfo>
54
+ <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
55
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
56
+ <ds:Reference URI="#_ba16587e-5f6c-4c2f-bad6-20767143844f">
57
+ <ds:Transforms>
58
+ <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
59
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
60
+ </ds:Transforms>
61
+ <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
62
+ <ds:DigestValue>r4VorpYHSk5ZElNt9BzrIwuwwV4=</ds:DigestValue>
63
+ </ds:Reference>
64
+ </ds:SignedInfo>
65
+ <ds:SignatureValue>cNSoYTNmp7N2vtTNb9VNkhTgvF/aF0hNWzGkw1+7oy5CIxWYu4sDauY1S42TNRZjsd/m7DL5IDG02YdLe2PfUMNiA6k1nxMcP7C2ql2Wrp2cwTRFTmDEHO9TcSaKbX8owvQGmn492qOQ9ziwUgBleomM2aKsp+jtO+AHi4VObOmuxBcahAB5Krw0DLsWxfM1pAYZygaQfnf+QM6k1BwIIIRutPLIRvn0XeBjLynB5JAHc6W7j8ii2rOCKgOVp5b4pnKsm4Y9gcv0jQQILwSVYWxN6p+LkhKCxmXBhiug+VfoH9BsilItfXSoEial4cBP7EC5J9Nxn1twj2HeKohSig==</ds:SignatureValue>
66
+ <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
67
+ <X509Data>
68
+ <X509Certificate>MIIC3DCCAcSgAwIBAgIQZK0UpOPhlpxBNKzZ8XOwRzANBgkqhkiG9w0BAQsFADAqMSgwJgYDVQQDEx9BREZTIFNpZ25pbmcgLSBmcy5ham1pY2hhZWwubmV0MB4XDTE1MDcwMjIxMzYyOVoXDTE2MDcwMTIxMzYyOVowKjEoMCYGA1UEAxMfQURGUyBTaWduaW5nIC0gZnMuYWptaWNoYWVsLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyCCmkytGlVsg8H2zUo3zZ8p/2tuq/f1QOw9h9rh3EKaJrX4+Hk60rzjNiwmSfnpqcYDS7MPKTX2UdngV6HZsnEQD5S2vaNTncGIkyvAi6jAUo9fYfuSIZxQyoP6wFqTMYHrHJhjZEuExPNAKEFmR0oozSzCFOZH0oJCr1b1jwb5Fi7M1uN98DPbRQg0CbTdV2EJzj2cnMX7v1aohwUg8rUo3yvexLuvcJSXy4kRWCNRTtVOo57NeE2pECdlCZQOMCnpps7AfaEUkLQL8Jbi8lJyNZ65I19+wKYSb1mx60c2rotgkQIN6v5/WgnXdA3Dok9gbjlqoK9Ew3rzAmr4q8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEACsiXJk+V+rBOJJkaVss8qDqysT2H6PcV6vjWs+fk84edYqhpNz9wimLOa/afQSVgcfMAbs6/CG3STmGRvQ+wDhYsVBzX3hzur741IYQclz9eEJtSrPNG04/zqq2/9LP81reIEksfKhgPho33PYop3cSorO8ogbxm10/bFgi99Lz1tTJkxpGhjxOdrMrZ5gU2r9NfyeL6Z9hmiixHQXruQdQSTeUsOVnx97mLO9fjKbeeeGrI5x8xsVWYDqRlhfXamwaglXu8ptf7frY/+FLoVKSAlGSV+GMw2Q53s4h91o4hPsNxanZD474n2soP3MKqeIyqVtafboooZ85PGh2kvg==</X509Certificate>
69
+ </X509Data>
70
+ </KeyInfo>
71
+ </ds:Signature>
72
+ </saml:Assertion>
73
+ </t:RequestedSecurityToken>
74
+ <t:RequestedAttachedReference>
75
+ <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1">
76
+ <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">_ba16587e-5f6c-4c2f-bad6-20767143844f</o:KeyIdentifier>
77
+ </o:SecurityTokenReference>
78
+ </t:RequestedAttachedReference>
79
+ <t:RequestedUnattachedReference>
80
+ <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1">
81
+ <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">_ba16587e-5f6c-4c2f-bad6-20767143844f</o:KeyIdentifier>
82
+ </o:SecurityTokenReference>
83
+ </t:RequestedUnattachedReference>
84
+ <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
85
+ <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
86
+ <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
87
+ </t:RequestSecurityTokenResponse>
88
+ </s:Body>
89
+ </s:Envelope>
@@ -0,0 +1,53 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Copyright (c) 2015 Micorosft Corporation
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #-------------------------------------------------------------------------------
22
+
23
+ require_relative './support/fake_token_endpoint'
24
+
25
+ require 'simplecov'
26
+ require 'webmock/rspec'
27
+
28
+ # The coverage tool only considers code after this line.
29
+ SimpleCov.start do
30
+ add_filter 'spec' # ignore spec files
31
+ end
32
+
33
+ require 'adal'
34
+
35
+ # Don't print any logs from ADAL::Logger.
36
+ ADAL::Logging.log_output = File.open(File::NULL, 'w')
37
+
38
+ # Unit tests do not need network access. Any attempts to access the network
39
+ # will throw exceptions.
40
+ WebMock.disable_net_connect!(allow_localhost: true)
41
+
42
+ RSpec.configure do |config|
43
+ config.before(:each) do
44
+ # Any network requests matching these RegExps will be redirected to the mock
45
+ # Sinatra servers in $DIR/spec/support. Any network requests that don't
46
+ # match will attempt to access the network and raise exceptions.
47
+ stub_request(:post, %r{oauth2/token}).to_rack(FakeTokenEndpoint)
48
+ end
49
+
50
+ config.expect_with :rspec do |c|
51
+ c.syntax = :expect
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Copyright (c) 2015 Micorosft Corporation
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #-------------------------------------------------------------------------------
22
+
23
+ # All of the data that the fake token and authority endpoints support. It is
24
+ # separated into its own module so that it can be used as a mix-in in test
25
+ # classes.
26
+ module FakeData
27
+ AUTH_CODE = 'auth_code_1'
28
+ AUTHORITY = 'login.windows.net'
29
+ ASSERTION = 'header.payload.crypto'
30
+ CLIENT_ID = 'client_id_1'
31
+ CLIENT_SECRET = 'client_secret_1'
32
+ PASSWORD = 'password1'
33
+ REDIRECT_URI = 'http://redirect1.com'
34
+ REFRESH_TOKEN = 'refresh_token_1'
35
+ RETURNED_TOKEN = 'a new token'
36
+ RESOURCE = 'resource'
37
+ TENANT = 'TENANT1'
38
+ USERNAME = 'user1@TENANT1'
39
+ USER_ASSERTION = 'user_assertion_1'
40
+ end
@@ -0,0 +1,108 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Copyright (c) 2015 Micorosft Corporation
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #-------------------------------------------------------------------------------
22
+
23
+ require_relative './fake_data'
24
+
25
+ require 'json'
26
+ require 'jwt'
27
+ require 'sinatra/base'
28
+
29
+ # A token endpoint that only recognizes one tenant and client id.
30
+ class FakeTokenEndpoint < Sinatra::Base
31
+ include FakeData
32
+
33
+ # Taken from RFC 6749 4.1.2.1.
34
+ module ErrorResponseCodes
35
+ INVALID_REQUEST = 'invalid_request'
36
+ INVALID_CLIENT = 'invalid_client'
37
+ INVALID_GRANT = 'invalid_grant'
38
+ UNAUTHORIZED_CLIENT = 'unauthorized_client'
39
+ UNSUPPORTED_GRANT_TYPE = 'unsupported_grant_type'
40
+ end
41
+
42
+ DEFAULT_EXPIRATION = 3600
43
+ DEFAULT_ID_TOKEN = JWT.encode({ email: USERNAME }, '')
44
+ DEFAULT_TOKEN_TYPE = 'Bearer'
45
+
46
+ post '/:tenant/oauth2/token' do
47
+ if TENANT != params[:tenant] || CLIENT_ID != params[:client_id]
48
+ error_oauth_response(ErrorResponseCodes::INVALID_CLIENT)
49
+ elsif params.key?('code') && AUTH_CODE == params['code'] &&
50
+ REDIRECT_URI == params['redirect_uri']
51
+ successful_oauth_response
52
+ elsif params['code']
53
+ error_oauth_response(ErrorResponseCodes::INVALID_GRANT)
54
+ elsif params['refresh_token'] && REFRESH_TOKEN == params['refresh_token']
55
+ successful_oauth_response
56
+ elsif params['refresh_token']
57
+ error_oauth_response(ErrorResponseCodes::UNAUTHORIZED_CLIENT)
58
+ elsif params['client_secret'] && CLIENT_SECRET == params['client_secret']
59
+ successful_oauth_response
60
+ elsif params.key? 'client_secret'
61
+ error_oauth_response(ErrorResponseCodes::INVALID_CLIENT)
62
+ else
63
+ error_oauth_response(ErrorResponseCodes::INVALID_REQUEST)
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def error_oauth_response(code, description = 'Error from fake endpoint')
70
+ { error: code, error_description: description }.to_json
71
+ end
72
+
73
+ def oauth_response(tenant)
74
+ { access_token: 'test_access_token',
75
+ token_type: 'BEARER',
76
+ tenant: tenant
77
+ }
78
+ end
79
+
80
+ def successful_oauth_response(opts = {})
81
+ res = { access_token: opts[:access_token] || RETURNED_TOKEN,
82
+ token_type: opts[:token_type] || DEFAULT_TOKEN_TYPE,
83
+ id_token: opts[:id_token] || DEFAULT_ID_TOKEN,
84
+ resource: params[:resource],
85
+ expires_in: opts[:expires_in] || DEFAULT_EXPIRATION }
86
+ res[:refresh_token] = opts[:refresh_token] if opts.key? :refresh_token
87
+ res.to_json
88
+ end
89
+
90
+ def try_auth_code(data, params)
91
+ return unless params.key? 'code'
92
+ if (data['codes'].key? params[:code]) &&
93
+ data['codes'][params['code']] == params[:redirect_uri]
94
+ successful_oauth_response
95
+ else
96
+ error_oauth_response(ErrorResponseCodes::INVALID_GRANT)
97
+ end
98
+ end
99
+
100
+ def try_client_secret(data, params)
101
+ return unless params.key? 'client_secret'
102
+ if data['client_secret'] == params[:client_secret]
103
+ successful_oauth_response
104
+ else
105
+ error_oauth_response(ErrorResponseCodes::INVALID_CLIENT)
106
+ end
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,265 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adal
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Microsoft Corporation
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: uri_template
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.32'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.32'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '1.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '1.21'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '1.21'
139
+ description: Windows Azure Active Directory authentication client library
140
+ email: nugetaad@microsoft.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - .gitignore
146
+ - .rubocop.yml
147
+ - .travis.yml
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - adal.gemspec
153
+ - contributing.md
154
+ - lib/adal.rb
155
+ - lib/adal/authentication_context.rb
156
+ - lib/adal/authentication_parameters.rb
157
+ - lib/adal/authority.rb
158
+ - lib/adal/cache_driver.rb
159
+ - lib/adal/cached_token_response.rb
160
+ - lib/adal/client_assertion.rb
161
+ - lib/adal/client_assertion_certificate.rb
162
+ - lib/adal/client_credential.rb
163
+ - lib/adal/core_ext.rb
164
+ - lib/adal/core_ext/hash.rb
165
+ - lib/adal/jwt_parameters.rb
166
+ - lib/adal/logger.rb
167
+ - lib/adal/logging.rb
168
+ - lib/adal/memory_cache.rb
169
+ - lib/adal/mex_request.rb
170
+ - lib/adal/mex_response.rb
171
+ - lib/adal/noop_cache.rb
172
+ - lib/adal/oauth_request.rb
173
+ - lib/adal/request_parameters.rb
174
+ - lib/adal/self_signed_jwt_factory.rb
175
+ - lib/adal/templates/rst.13.xml.erb
176
+ - lib/adal/templates/rst.2005.xml.erb
177
+ - lib/adal/token_request.rb
178
+ - lib/adal/token_response.rb
179
+ - lib/adal/user_assertion.rb
180
+ - lib/adal/user_credential.rb
181
+ - lib/adal/user_identifier.rb
182
+ - lib/adal/user_information.rb
183
+ - lib/adal/util.rb
184
+ - lib/adal/version.rb
185
+ - lib/adal/wstrust_request.rb
186
+ - lib/adal/wstrust_response.rb
187
+ - lib/adal/xml_namespaces.rb
188
+ - samples/authorization_code_example/README.md
189
+ - samples/authorization_code_example/web_app.rb
190
+ - samples/client_assertion_certificate_example/README.md
191
+ - samples/client_assertion_certificate_example/app.rb
192
+ - samples/on_behalf_of_example/README.md
193
+ - samples/on_behalf_of_example/native_app.rb
194
+ - samples/on_behalf_of_example/web_api.rb
195
+ - samples/user_credentials_example/README.md
196
+ - samples/user_credentials_example/app.rb
197
+ - spec/adal/authentication_context_spec.rb
198
+ - spec/adal/authentication_parameters_spec.rb
199
+ - spec/adal/authority_spec.rb
200
+ - spec/adal/cache_driver_spec.rb
201
+ - spec/adal/cached_token_response_spec.rb
202
+ - spec/adal/client_assertion_certificate_spec.rb
203
+ - spec/adal/client_assertion_spec.rb
204
+ - spec/adal/core_ext/hash_spec.rb
205
+ - spec/adal/logging_spec.rb
206
+ - spec/adal/memory_cache_spec.rb
207
+ - spec/adal/mex_request_spec.rb
208
+ - spec/adal/mex_response_spec.rb
209
+ - spec/adal/self_signed_jwt_factory_spec.rb
210
+ - spec/adal/token_request_spec.rb
211
+ - spec/adal/token_response_spec.rb
212
+ - spec/adal/user_credential_spec.rb
213
+ - spec/adal/user_identifier_spec.rb
214
+ - spec/adal/wstrust_request_spec.rb
215
+ - spec/adal/wstrust_response_spec.rb
216
+ - spec/fixtures/mex/insecureaddress.xml
217
+ - spec/fixtures/mex/invalid_namespaces.xml
218
+ - spec/fixtures/mex/malformed.xml
219
+ - spec/fixtures/mex/microsoft.xml
220
+ - spec/fixtures/mex/multiple_endpoints.xml
221
+ - spec/fixtures/mex/no_matching_bindings.xml
222
+ - spec/fixtures/mex/no_username_token_policies.xml
223
+ - spec/fixtures/mex/no_wstrust_endpoints.xml
224
+ - spec/fixtures/mex/only_13.xml
225
+ - spec/fixtures/mex/only_2005.xml
226
+ - spec/fixtures/oauth/error.json
227
+ - spec/fixtures/oauth/success.json
228
+ - spec/fixtures/oauth/success_with_id_token.json
229
+ - spec/fixtures/wstrust/error.xml
230
+ - spec/fixtures/wstrust/invalid_namespaces.xml
231
+ - spec/fixtures/wstrust/missing_security_tokens.xml
232
+ - spec/fixtures/wstrust/success.xml
233
+ - spec/fixtures/wstrust/token.xml
234
+ - spec/fixtures/wstrust/too_many_security_tokens.xml
235
+ - spec/fixtures/wstrust/unrecognized_token_type.xml
236
+ - spec/fixtures/wstrust/wstrust.13.xml
237
+ - spec/fixtures/wstrust/wstrust.2005.xml
238
+ - spec/spec_helper.rb
239
+ - spec/support/fake_data.rb
240
+ - spec/support/fake_token_endpoint.rb
241
+ homepage: http://github.com/AzureAD/azure-activedirectory-library-for-ruby
242
+ licenses:
243
+ - MIT
244
+ metadata: {}
245
+ post_install_message:
246
+ rdoc_options: []
247
+ require_paths:
248
+ - lib
249
+ required_ruby_version: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - '>='
252
+ - !ruby/object:Gem::Version
253
+ version: 2.1.0
254
+ required_rubygems_version: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - '>='
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ requirements: []
260
+ rubyforge_project:
261
+ rubygems_version: 2.0.14
262
+ signing_key:
263
+ specification_version: 4
264
+ summary: ADAL for Ruby
265
+ test_files: []