Skip to content

Commit

Permalink
Remove any extra quotes that were stored with legacy tokens
Browse files Browse the repository at this point in the history
(closes #129)
  • Loading branch information
bhousel committed Apr 26, 2024
1 parent a597d52 commit 44e3703
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ _Breaking changes, which may affect downstream projects, are marked with a_ ⚠
[#xxx]: https://github.com/osmlab/osm-auth/issues/xxx
-->

## 2.5.0
##### 2024-Apr-26
* Remove any extra quotes that were stored with legacy tokens ([#129])
* Allow locale to be passed to login page ([#23], [#130], thanks [@k-yle])

[#23]: https://github.com/osmlab/osm-auth/issues/23
[#129]: https://github.com/osmlab/osm-auth/issues/129
[#130]: https://github.com/osmlab/osm-auth/issues/130
[@k-yle]: https://github.com/k-yle


## 2.4.0
##### 2024-Jan-04
* Remove `store` dependency ([#126])
Expand Down
18 changes: 13 additions & 5 deletions dist/osm-auth.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ function osmAuth(o) {
};
}
function token(k, v) {
if (arguments.length === 1)
return _store.getItem(o.url + k);
else if (arguments.length === 2)
return _store.setItem(o.url + k, v);
var key = o.url + k;
if (arguments.length === 1) {
var val = _store.getItem(key) || "";
return val.replace(/"/g, "");
} else if (arguments.length === 2) {
if (v) {
return _store.setItem(key, v);
} else {
return _store.removeItem(key);
}
}
}
oauth.authenticated = function() {
return !!token("oauth2_access_token");
Expand Down Expand Up @@ -123,7 +130,8 @@ function osmAuth(o) {
scope: o.scope,
state,
code_challenge: pkce.code_challenge,
code_challenge_method: pkce.code_challenge_method
code_challenge_method: pkce.code_challenge_method,
locale: o.locale || ""
});
if (o.singlepage) {
if (_store.isMocked) {
Expand Down
4 changes: 2 additions & 2 deletions dist/osm-auth.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/osm-auth.iife.js

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

6 changes: 3 additions & 3 deletions dist/osm-auth.iife.js.map

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions src/osm-auth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ export function osmAuth(o) {
* @return {string?} If getting, returns the stored value or `null`. If setting, returns `undefined`.
*/
function token(k, v) {
if (arguments.length === 1) return _store.getItem(o.url + k);
else if (arguments.length === 2) return _store.setItem(o.url + k, v);
var key = o.url + k;
if (arguments.length === 1) {
var val = _store.getItem(key) || '';
// Note: legacy tokens might be wrapped in double quotes - remove them, see #129
return val.replace(/"/g, '');

} else if (arguments.length === 2) {
if (v) {
return _store.setItem(key, v);
} else {
return _store.removeItem(key);
}
}
}


Expand Down Expand Up @@ -195,7 +206,7 @@ export function osmAuth(o) {
state: state,
code_challenge: pkce.code_challenge,
code_challenge_method: pkce.code_challenge_method,
locale: o.locale || "",
locale: o.locale || '',
});

if (o.singlepage) {
Expand Down

0 comments on commit 44e3703

Please sign in to comment.