Advertisement
Guest User

Consent.Index.fs

a guest
Jun 29th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.63 KB | None | 0 0
  1. module Consent.Index
  2.  
  3. open System.Web
  4. open canopy.classic
  5.  
  6. // https://localhost:23501/connect/authorize?client_id=overlay-client&redirect_uri=&response_type=code&scope=openid%20profile%20api1%20roles&state=fe737009777944db9de80baf370105a1&code_challenge=_ubt4YbQ-7qU1tho4STnaDAG6RcRbKphIt3SH4mwq5c&code_challenge_method=S256
  7.  
  8. let private authroizeUrl = EnvProps.baseUri + "/connect/authorize"
  9. let private responseType = "code"
  10. let private scope = "openid profile api1 roles"
  11. let private state = "fe737009777944db9de80baf370105a1"
  12. let private codeChallenge = "_ubt4YbQ-7qU1tho4STnaDAG6RcRbKphIt3SH4mwq5c"
  13. let private codeChallengeMethod = "S256"
  14.  
  15. let createConsentUrl clientId redirectUri =
  16.     [
  17.         authroizeUrl;
  18.         "?client_id="; clientId;
  19.         "&redirect_uri="; redirectUri;
  20.         "&response_type="; responseType;
  21.         "&scope="; HttpUtility.HtmlDecode scope;
  22.         "&state="; state;
  23.         "&code_challenge="; codeChallenge;
  24.         "&code_challenge_method="; codeChallengeMethod;
  25.     ]
  26.     |> String.concat ""
  27.  
  28. let navigateToConsentPage clientId redirectUri =
  29.     createConsentUrl clientId redirectUri
  30.     |> fun consentUrl ->
  31.         System.Console.WriteLine consentUrl
  32.         url consentUrl
  33.  
  34.  
  35. let pageTitle = ".page-title"
  36. let pageDescription = ".consent-page-description"
  37. let yesAllowAccess = ".consent-form #yes"
  38. let noToAccess = ".consent-form #no"
  39.  
  40. let personalInfoHeading = ".personal-info .panel-heading"
  41. let userIdentitiferLabel = "label:has(#scopes_openid)"
  42. let userIdentitiferCheckbox = "#scopes_openid"
  43. let userIdentitiferRequiredLabel = "li:has(label:has(#scopes_openid)) span em"
  44. let userProfileLabel = "label:has(#scopes_profile)"
  45. let userProfileCheckbox = "#scopes_profile"
  46. let userProfilePermissionDetails = ".consent-description [for=\"scopes_profile\"]"
  47.  
  48. let applicationAccessHeading = ".application-access .panel-heading"
  49. let apiApplciationAccess = "#scopes_api1"
  50. let apiApplciationAccessLabel = "label:has(#scopes_api1)"
  51. let rolesApplicationAccess = "#scopes_roles"
  52. let rolesApplicationAccessLabel = "label:has(#scopes_roles)"
  53.  
  54. let rememberDecisionCheckbox = "#RememberConsent"
  55. let rememberDecisionLabel = "label:has(#RememberConsent)"
  56.  
  57. let clientUrl = "#client-url"
  58. let clientUrlByHref href = "#client-url[href=\"" + href + "\"]"
  59.  
  60. let acceptConsentToClient clientId redirectUrl =
  61.     navigateToConsentPage clientId redirectUrl
  62.     try
  63.         elementWithText yesAllowAccess "Yes" |> ignore;
  64.         printfn "Client Consent page found, Allowing Access."
  65.         click yesAllowAccess
  66.     with  
  67.         | _ -> printfn "Client Consent could have already been given..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement