Skip to content

Commit

Permalink
Merge pull request #10 from Omarabdul3ziz/github_auth
Browse files Browse the repository at this point in the history
fix github redirection
  • Loading branch information
Omarabdul3ziz authored Sep 19, 2021
2 parents b1f2b87 + 4c65afb commit d92aab7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 35 deletions.
60 changes: 30 additions & 30 deletions services/client/src/views/Github.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<div>
<div>
<button type="submit" class="btn btn-primary">
<a href="http://127.0.0.1:5000/auth/github">Login with GitHub</a>
<a href="https://127.0.0.1:5000/auth/github">Login with GitHub</a>
</button>
</div>
<br />
<div>
<!-- <div>
<button type="submit" class="btn btn-primary" @click="githubLogin">
Login with GitHub
</button>
</div>
</div> -->
</div>
</template>

Expand All @@ -22,37 +22,37 @@ import VueAxios from "vue-axios";
Vue.use(VueAxios, axios);
export default {
name: "Github",
data() {
return {
baseUrl: this.$store.state.api_url,
};
},
created() {
// this.githubLogin();
},
methods: {
fetchTocken() {
const path = this.baseUrl + "/auth/github";
fetch(path).then((response) => console.log(response));
},
// data() {
// return {
// baseUrl: this.$store.state.api_url,
// };
// },
// created() {
// // this.githubLogin();
// },
// methods: {
// fetchTocken() {
// const path = this.baseUrl + "/auth/github";
// fetch(path).then((response) => console.log(response));
// },
githubLogin() {
const path = this.baseUrl + "/auth/github";
Vue.axios.get(path).then((response) => {
const token = response.data.access_token;
console.log(token);
// githubLogin() {
// const path = this.baseUrl + "/auth/github";
// Vue.axios.get(path).then((response) => {
// const token = response.data.access_token;
// console.log(token);
// add to local storage
localStorage.setItem("access_token", token);
// // add to local storage
// localStorage.setItem("access_token", token);
// update the store state token
this.$store.commit("updateToken", token);
// // update the store state token
// this.$store.commit("updateToken", token);
// redirect for next route
this.$router.push({ name: "Todo" });
});
},
},
// // redirect for next route
// this.$router.push({ name: "Todo" });
// });
// },
// },
};
</script>

Expand Down
25 changes: 20 additions & 5 deletions services/server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ def github_login():
if account_info.ok:
username = account_info.json()['login']

params = {
"username": username,
}

url_params = urlencode(params)
return redirect(f"https://127.0.0.1:5000/auth/callback?{url_params}")

@auth_blueprint.route('/callback')
def github_callback():
username = request.args.get("username")

# fetch user from db
user = users.find_one({'username': username})

Expand All @@ -123,12 +134,16 @@ def github_login():
access_token = create_access_token(identity=username)

# default set cookie
response = jsonify(access_token=access_token)
set_access_cookies(response, access_token)
# response = jsonify(access_token=access_token)
# set_access_cookies(response, access_token)

# my custome set
# response = make_response(redirect(url_for("index")))
# response.set_cookie('access_token_cookie', access_token)
# # my custome set
# # response = make_response(redirect(url_for("index")))
# # response.set_cookie('access_token_cookie', access_token)
# return response

response = make_response(redirect("http://127.0.0.1:8080/"))
response.set_cookie("access_token_cookie", access_token)
return response

#########################################
Expand Down

0 comments on commit d92aab7

Please sign in to comment.