Skip to content

Commit

Permalink
refactor: provide provider information with settings
Browse files Browse the repository at this point in the history
This removes one http request when loading the information for login screen
  • Loading branch information
thathoff committed May 4, 2021
1 parent 6908135 commit 93c4367
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct()
$this->providers = new ProvidersManager($this->kirby);
}

public function providers()
private function providers()
{
return $this->providers->count() > 0 ?
$this->providers->toArray(
Expand All @@ -39,6 +39,7 @@ public function settings()
return [
'onlyOauth' => $this->kirby->option('thathoff.oauth.onlyOauth', false),
'enabled' => count($this->providers) > 0,
'providers' => $this->providers(),
];
}

Expand Down Expand Up @@ -125,7 +126,7 @@ private function loginUser(ResourceOwnerInterface $oauthUser)
$oauthUserData = $oauthUser->toArray();

$vars = ['name', 'email', 'email_verified', 'hd'];

//Azure Active Directory doesn't use "email" for email address, but "upn" for User Principal Name, and the email is always verified in Azure AD tenant
if(isset($oauthUserData["upn"])) {
$email = $oauthUserData["upn"];
Expand Down
9 changes: 5 additions & 4 deletions src/components/LoginScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ export default {
data() {
return {
settings: {},
providers: [],
error: null
};
},
created() {
this.load();
},
computed: {
providers () {
return Object.values(this.settings.providers)
}
},
methods: {
async load() {
this.settings = await this.$api.get("oauth/settings");
this.providers = Object.values(
await this.$api.get("oauth/providers")
);
this.error = (await this.$api.get("oauth/oauthError")).msg;
}
}
Expand Down

0 comments on commit 93c4367

Please sign in to comment.