Access-control-allow-origin is not present in Okta authorization URL





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am developing rest services and consuming those by ajax.



Now I have secured my web service with okta and it is working well when I invoke from chrome or any browser. But If I tried to consume from Jquery/ajax, I am getting below error. Could anyone Please help on this.



I have used python, flask to develop web services and used OpenIdConnect(flask_oidc) for authentication.
Piece of code



app = Flask(__name__)
app.config["OIDC_CLIENT_SECRETS"] =
services_dir+"okta/client_secrets.json"
app.config["OIDC_COOKIE_SECURE"] = False
app.config["OIDC_CALLBACK_ROUTE"] = "/oidc/callback"
app.config["OIDC_SCOPES"] = ["openid", "profile"]
app.config["SECRET_KEY"] = "********"
app.config['CORS_HEADERS'] = 'Content-Type'

oidc = OpenIDConnect(app)
cors = CORS(app, resources={r"/ai/*": {"origins": "*"}})


@app.before_request
def before_request():
print("Before request",oidc.user_loggedin)
if oidc.user_loggedin:
#print("access token",oidc.get_access_token())
print("sub",oidc.user_getinfo(["name"]))
g.user = oidc.user_getfield("name")
else:
g.user = None


@app.route('/ai/docsearchStatus', methods = ['GET'])
@cross_origin(origin='*')
@oidc.require_login
def getHealthstatus():
response = {}
response['user'] = g.user
response=json.dumps(response);
return response


Jquery Ajax code:



$.ajax({     
type:"GET",
url: "https://https://example.com/ai/docsearchStatus",

beforeSend: function(xhr) {
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success:function(data, textStatus, XMLHttpRequest){


},
error:function(XMLHttpRequest, textStatus, errorThrown){
//fnHideLoader();
}
});


If I call https:///ai/docsearchStatus it is working properly(Redirecting--authenticating -- got response).
When I tried from ajax I am getting below URL:
Error is :



  Failed to load https://mycompany.okta.com/oauth2/ausl2cu6foKJx4WXS0x7/v1/authorize? Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://example.com’ is therefore not allowed access.


Can any one help this. I have even configured https://example.com in okta admin through API > Trusted Origins.










share|improve this question




















  • 1





    Access control headers have to be set by endpoint server in response. You can't set them in the client side request. You can use your server as a proxy to make the api request and call your server with the ajax and return the api data to the ajax

    – charlietfl
    Nov 16 '18 at 21:03













  • Thanks for your quick reply. I have enabled cors in my services you can see in above code. if I remove @oidc.require_login in above service it will work. Okta is not allowing.

    – user1632980
    Nov 16 '18 at 21:54











  • So If I add origin as trusted in okta admin, It will resolve the problem. In that case I have already added.

    – user1632980
    Nov 19 '18 at 23:22


















0















I am developing rest services and consuming those by ajax.



Now I have secured my web service with okta and it is working well when I invoke from chrome or any browser. But If I tried to consume from Jquery/ajax, I am getting below error. Could anyone Please help on this.



I have used python, flask to develop web services and used OpenIdConnect(flask_oidc) for authentication.
Piece of code



app = Flask(__name__)
app.config["OIDC_CLIENT_SECRETS"] =
services_dir+"okta/client_secrets.json"
app.config["OIDC_COOKIE_SECURE"] = False
app.config["OIDC_CALLBACK_ROUTE"] = "/oidc/callback"
app.config["OIDC_SCOPES"] = ["openid", "profile"]
app.config["SECRET_KEY"] = "********"
app.config['CORS_HEADERS'] = 'Content-Type'

oidc = OpenIDConnect(app)
cors = CORS(app, resources={r"/ai/*": {"origins": "*"}})


@app.before_request
def before_request():
print("Before request",oidc.user_loggedin)
if oidc.user_loggedin:
#print("access token",oidc.get_access_token())
print("sub",oidc.user_getinfo(["name"]))
g.user = oidc.user_getfield("name")
else:
g.user = None


@app.route('/ai/docsearchStatus', methods = ['GET'])
@cross_origin(origin='*')
@oidc.require_login
def getHealthstatus():
response = {}
response['user'] = g.user
response=json.dumps(response);
return response


Jquery Ajax code:



$.ajax({     
type:"GET",
url: "https://https://example.com/ai/docsearchStatus",

beforeSend: function(xhr) {
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success:function(data, textStatus, XMLHttpRequest){


},
error:function(XMLHttpRequest, textStatus, errorThrown){
//fnHideLoader();
}
});


If I call https:///ai/docsearchStatus it is working properly(Redirecting--authenticating -- got response).
When I tried from ajax I am getting below URL:
Error is :



  Failed to load https://mycompany.okta.com/oauth2/ausl2cu6foKJx4WXS0x7/v1/authorize? Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://example.com’ is therefore not allowed access.


Can any one help this. I have even configured https://example.com in okta admin through API > Trusted Origins.










share|improve this question




















  • 1





    Access control headers have to be set by endpoint server in response. You can't set them in the client side request. You can use your server as a proxy to make the api request and call your server with the ajax and return the api data to the ajax

    – charlietfl
    Nov 16 '18 at 21:03













  • Thanks for your quick reply. I have enabled cors in my services you can see in above code. if I remove @oidc.require_login in above service it will work. Okta is not allowing.

    – user1632980
    Nov 16 '18 at 21:54











  • So If I add origin as trusted in okta admin, It will resolve the problem. In that case I have already added.

    – user1632980
    Nov 19 '18 at 23:22














0












0








0








I am developing rest services and consuming those by ajax.



Now I have secured my web service with okta and it is working well when I invoke from chrome or any browser. But If I tried to consume from Jquery/ajax, I am getting below error. Could anyone Please help on this.



I have used python, flask to develop web services and used OpenIdConnect(flask_oidc) for authentication.
Piece of code



app = Flask(__name__)
app.config["OIDC_CLIENT_SECRETS"] =
services_dir+"okta/client_secrets.json"
app.config["OIDC_COOKIE_SECURE"] = False
app.config["OIDC_CALLBACK_ROUTE"] = "/oidc/callback"
app.config["OIDC_SCOPES"] = ["openid", "profile"]
app.config["SECRET_KEY"] = "********"
app.config['CORS_HEADERS'] = 'Content-Type'

oidc = OpenIDConnect(app)
cors = CORS(app, resources={r"/ai/*": {"origins": "*"}})


@app.before_request
def before_request():
print("Before request",oidc.user_loggedin)
if oidc.user_loggedin:
#print("access token",oidc.get_access_token())
print("sub",oidc.user_getinfo(["name"]))
g.user = oidc.user_getfield("name")
else:
g.user = None


@app.route('/ai/docsearchStatus', methods = ['GET'])
@cross_origin(origin='*')
@oidc.require_login
def getHealthstatus():
response = {}
response['user'] = g.user
response=json.dumps(response);
return response


Jquery Ajax code:



$.ajax({     
type:"GET",
url: "https://https://example.com/ai/docsearchStatus",

beforeSend: function(xhr) {
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success:function(data, textStatus, XMLHttpRequest){


},
error:function(XMLHttpRequest, textStatus, errorThrown){
//fnHideLoader();
}
});


If I call https:///ai/docsearchStatus it is working properly(Redirecting--authenticating -- got response).
When I tried from ajax I am getting below URL:
Error is :



  Failed to load https://mycompany.okta.com/oauth2/ausl2cu6foKJx4WXS0x7/v1/authorize? Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://example.com’ is therefore not allowed access.


Can any one help this. I have even configured https://example.com in okta admin through API > Trusted Origins.










share|improve this question
















I am developing rest services and consuming those by ajax.



Now I have secured my web service with okta and it is working well when I invoke from chrome or any browser. But If I tried to consume from Jquery/ajax, I am getting below error. Could anyone Please help on this.



I have used python, flask to develop web services and used OpenIdConnect(flask_oidc) for authentication.
Piece of code



app = Flask(__name__)
app.config["OIDC_CLIENT_SECRETS"] =
services_dir+"okta/client_secrets.json"
app.config["OIDC_COOKIE_SECURE"] = False
app.config["OIDC_CALLBACK_ROUTE"] = "/oidc/callback"
app.config["OIDC_SCOPES"] = ["openid", "profile"]
app.config["SECRET_KEY"] = "********"
app.config['CORS_HEADERS'] = 'Content-Type'

oidc = OpenIDConnect(app)
cors = CORS(app, resources={r"/ai/*": {"origins": "*"}})


@app.before_request
def before_request():
print("Before request",oidc.user_loggedin)
if oidc.user_loggedin:
#print("access token",oidc.get_access_token())
print("sub",oidc.user_getinfo(["name"]))
g.user = oidc.user_getfield("name")
else:
g.user = None


@app.route('/ai/docsearchStatus', methods = ['GET'])
@cross_origin(origin='*')
@oidc.require_login
def getHealthstatus():
response = {}
response['user'] = g.user
response=json.dumps(response);
return response


Jquery Ajax code:



$.ajax({     
type:"GET",
url: "https://https://example.com/ai/docsearchStatus",

beforeSend: function(xhr) {
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success:function(data, textStatus, XMLHttpRequest){


},
error:function(XMLHttpRequest, textStatus, errorThrown){
//fnHideLoader();
}
});


If I call https:///ai/docsearchStatus it is working properly(Redirecting--authenticating -- got response).
When I tried from ajax I am getting below URL:
Error is :



  Failed to load https://mycompany.okta.com/oauth2/ausl2cu6foKJx4WXS0x7/v1/authorize? Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://example.com’ is therefore not allowed access.


Can any one help this. I have even configured https://example.com in okta admin through API > Trusted Origins.







jquery ajax flask okta oidc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 21:52









wahwahwah

2,53111231




2,53111231










asked Nov 16 '18 at 20:55









user1632980user1632980

89118




89118








  • 1





    Access control headers have to be set by endpoint server in response. You can't set them in the client side request. You can use your server as a proxy to make the api request and call your server with the ajax and return the api data to the ajax

    – charlietfl
    Nov 16 '18 at 21:03













  • Thanks for your quick reply. I have enabled cors in my services you can see in above code. if I remove @oidc.require_login in above service it will work. Okta is not allowing.

    – user1632980
    Nov 16 '18 at 21:54











  • So If I add origin as trusted in okta admin, It will resolve the problem. In that case I have already added.

    – user1632980
    Nov 19 '18 at 23:22














  • 1





    Access control headers have to be set by endpoint server in response. You can't set them in the client side request. You can use your server as a proxy to make the api request and call your server with the ajax and return the api data to the ajax

    – charlietfl
    Nov 16 '18 at 21:03













  • Thanks for your quick reply. I have enabled cors in my services you can see in above code. if I remove @oidc.require_login in above service it will work. Okta is not allowing.

    – user1632980
    Nov 16 '18 at 21:54











  • So If I add origin as trusted in okta admin, It will resolve the problem. In that case I have already added.

    – user1632980
    Nov 19 '18 at 23:22








1




1





Access control headers have to be set by endpoint server in response. You can't set them in the client side request. You can use your server as a proxy to make the api request and call your server with the ajax and return the api data to the ajax

– charlietfl
Nov 16 '18 at 21:03







Access control headers have to be set by endpoint server in response. You can't set them in the client side request. You can use your server as a proxy to make the api request and call your server with the ajax and return the api data to the ajax

– charlietfl
Nov 16 '18 at 21:03















Thanks for your quick reply. I have enabled cors in my services you can see in above code. if I remove @oidc.require_login in above service it will work. Okta is not allowing.

– user1632980
Nov 16 '18 at 21:54





Thanks for your quick reply. I have enabled cors in my services you can see in above code. if I remove @oidc.require_login in above service it will work. Okta is not allowing.

– user1632980
Nov 16 '18 at 21:54













So If I add origin as trusted in okta admin, It will resolve the problem. In that case I have already added.

– user1632980
Nov 19 '18 at 23:22





So If I add origin as trusted in okta admin, It will resolve the problem. In that case I have already added.

– user1632980
Nov 19 '18 at 23:22












1 Answer
1






active

oldest

votes


















1














You need to define a Trusted Origin in Okta.



In your Okta Admin Console, browse to: Security -> API and choose the Trusted Origin tab.



You can then define a trusted origin for CORS.



Full disclosure: I work for Okta.






share|improve this answer
























  • Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

    – user1632980
    Nov 16 '18 at 21:55












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345248%2faccess-control-allow-origin-is-not-present-in-okta-authorization-url%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You need to define a Trusted Origin in Okta.



In your Okta Admin Console, browse to: Security -> API and choose the Trusted Origin tab.



You can then define a trusted origin for CORS.



Full disclosure: I work for Okta.






share|improve this answer
























  • Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

    – user1632980
    Nov 16 '18 at 21:55
















1














You need to define a Trusted Origin in Okta.



In your Okta Admin Console, browse to: Security -> API and choose the Trusted Origin tab.



You can then define a trusted origin for CORS.



Full disclosure: I work for Okta.






share|improve this answer
























  • Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

    – user1632980
    Nov 16 '18 at 21:55














1












1








1







You need to define a Trusted Origin in Okta.



In your Okta Admin Console, browse to: Security -> API and choose the Trusted Origin tab.



You can then define a trusted origin for CORS.



Full disclosure: I work for Okta.






share|improve this answer













You need to define a Trusted Origin in Okta.



In your Okta Admin Console, browse to: Security -> API and choose the Trusted Origin tab.



You can then define a trusted origin for CORS.



Full disclosure: I work for Okta.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 21:31









afitnerdafitnerd

63138




63138













  • Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

    – user1632980
    Nov 16 '18 at 21:55



















  • Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

    – user1632980
    Nov 16 '18 at 21:55

















Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

– user1632980
Nov 16 '18 at 21:55





Thanks for your reply, I have asked to my okta admin she confirmed that she has added trusted origin.

– user1632980
Nov 16 '18 at 21:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345248%2faccess-control-allow-origin-is-not-present-in-okta-authorization-url%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine