function OAuthClient(e,t,n){function f(){s=n,i=t,r=!1}function l(e){o=$.extend(!0,{},s.accessToken.headers),u=$.extend(!0,{},s.authorizationCode.headers),o.Authorization=c(o.Authorization,e),u.Authorization=c(u.Authorization,e),r=!0}function c(e,t){var n=!1,r="";if(!!e&&!!e.trim()){e=e.trim();var i=new RegExp("^"+e,"i");n=i.test(t)}return n?r=t:r=e+" "+t,r}function h(e){a=e}function p(t,n,u,f,l){var c;r||e.consoleLog("OAUTH ERROR("+i+"): AUTHORIZATION NOT INITIALIZED"),!!a&&!a.getUnitIdentifier()&&f.message&&f.message.header.attributess.deviceID&&a.setUnitIdentifier(f.message.header.attributess.deviceID);if(s.accessToken.urlPath!=undefined)c=a.oAuthServiceUrl.val+s.accessToken.urlPath,c=m(c);else{c=m(s.accessToken.url);if(!c)return}var h={header:undefined,requests:[]};h.header={metaData:f||null,source:i,responseMessageType:u,user:t};var p=$.extend(!0,{},s.accessToken.postFields);p.refresh_token=n;var p={grant_type:s.accessToken.postFields.grant_type,refresh_token:n,code:"",redirect_uri:""};h.requests[0]={url:c,method:"POST",headers:o,dataType:"json",data:JSON.stringify(p),contentType:"application/json"},l?e.urlFetch(h.requests,l):e.apiFetch(h)}function d(t,n,r){var o;if(s.accessToken.urlPath!=undefined)o=a.oAuthServiceUrl.val+s.accessToken.urlPath,o=m(o);else{o=m(s.accessToken.url);if(!o)return}var f={header:undefined,requests:[]};f.header={metaData:r,source:i,responseMessageType:n};var l=$.extend(!0,{},s.authorizationCode.postFields);l.code=t,f.requests[0]={url:o,method:"POST",headers:u,dataType:"json",contentType:"application/json",data:JSON.stringify(l)},e.apiFetch(f)}function v(t,n,r){var o,u={header:undefined,requests:[]};u.header={metaData:r,source:i,responseMessageType:n},o=$.extend(!0,{},s.userInfo.headers),o.Authorization+=t,u.requests[0]={url:s.userInfo.url,method:"GET",headers:o,dataType:"json"},e.apiFetch(u)}function m(e){var t=e;if(OAuthClient.Constants.URI_DEVICE_REGEXP.test(t)){if(!a.getUnitIdentifier())return null;t=t.replace(OAuthClient.Constants.URI_DEVICE_REGEXP,a.getUnitIdentifier())}if(OAuthClient.Constants.URI_ACCOUNT_REGEP.test(t)){if(!a.getMargeStreamingAccountId())return null;t=t.replace(OAuthClient.Constants.URI_ACCOUNT_REGEP,a.getMargeStreamingAccountId())}if(OAuthClient.Constants.URI_TOKEN_REGEXP.test(t)){if(!a.getClientSecretVersion())return null;t+=a.getClientSecretVersion()}return t}this.requestAccessToken=p,this.requestTokensFromAuthorizationCode=d,this.requestUserProfile=v,this.initAuthorization=l,this.setOAuthServiceUrlParameters=h;var r,i,s,o,u,a;f()}OAuthClient.Constants={URI_DEVICE_REGEXP:/%device%/,URI_ACCOUNT_REGEP:/%account%/,URI_TOKEN_REGEXP:/\/token\//},Object.freeze(OAuthClient.Constants);